Server security refers to the measures and practices implemented to protect servers from unauthorized access, data breaches, and other security threats. Server security involves implementing various security mechanisms to ensure the confidentiality, integrity, and availability of server resources.
In the context of AsyncAPI, securing servers ensures secure exchange of messages between clients and servers. While also protecting sensitive data, preventing unauthorized access, and maintaining the overall security of the API or server.
You can describe how your server is secured with the security property where you define which security schemes can be used with the server in context. Each server in the AsyncAPI document can have one or more security schemes declared. A security scheme defines a security requirement that must be satisfied to authorize an operation, such as an API key or a username and password.
Here is an example of adding security to your server, demonstrating that different servers can employ various security mechanisms:
1asyncapi: 3.0.02info:3 title: Streetlights Kafka API4 version: 1.0.05servers:6 scram-connections:7 host: 'test.mykafkacluster.org:18092'8 protocol: kafka-secure9 description: Test broker secured with scramSha25610 security:11 - $ref: '#/components/securitySchemes/saslScram'12 mtls-connections:13 host: 'test.mykafkacluster.org:28092'14 protocol: kafka-secure15 description: Test broker secured with X50916 security:17 - $ref: '#/components/securitySchemes/certs'18components:19 securitySchemes:20 saslScram:21 type: scramSha25622 description: Provide your username and password for SASL/SCRAM authentication23 certs:24 type: X50925 description: Download the certificate files from service provider
Here is an illustration of securing servers:
Here are some of the security schemes that AsyncAPI supports:
-
User/Password
type: userPassword -
API key (either as a user or as a password)
1type: apiKey2in: user -
X.509 certificate
type: X509 -
End-to-end encryption (either symmetric or asymmetric)
type: symmetricEncryption -
HTTP authentication
1type: http2scheme: basic -
HTTP API key
1type: httpApiKey2name: api_key3in: header -
JWT Bearer
1type: http2scheme: bearer3bearerFormat: JWT -
Implicit oauth2
1type: oauth22flows:3 implicit:4 authorizationUrl: https://example.com/api/oauth/dialog5 availableScopes:6 write:pets: modify pets in your account7 read:pets: read your pets8scopes:9 - 'write:pets' -
SASL (Simple Authentication and Security Layer) as defined in RFC4422
type: scramSha512
Although the security property is not mandatory, it is a good practice to always secure your server(s) in production. Similarly, having multiple security schemes declared does not necessarily mean that the server is more secure; it depends on other factors such as the protocol used, use case, business perspective, and more. Additionally, you can also add security at the operation level.