Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added content for securing operations #2172

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pages/docs/concepts/asyncapi-document/_section.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: AsyncAPI Document
weight: 50
---
81 changes: 81 additions & 0 deletions pages/docs/concepts/asyncapi-document/securing-operations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
title: 'Securing Operations'
weight: 120
---

The concept of server security implies that the security measures defined at the server level apply to all operations within all channels by default.

## Security Features

The security requirements specified at the server level are enforced consistently across the entire Asyncapi document. There may be situations where certain operations within specific channels require different security measures than the default server-level settings.

- To accommodate such scenarios, the AsyncAPI document allows you to use the `security` property at the `operation` level. This means users can define security requirements at both the global level and the operation (endpoint) level.

```yaml
channels:
AUTHORIZATION_REVOCATION:
address: AUTHORIZATION_REVOCATION
messages:
subscribe.message:
$ref: '#/components/messages/message'

security:
- apiKey: []
```

- One more way is when users don't use the `server` feature from AsyncAPI, and only include `channels` and `operations`. In this case, the user needs to specify the security of the operation within the `operations`.

```yaml
channels:
AUTHORIZATION_REVOCATION:
address: AUTHORIZATION_REVOCATION
messages:
subscribe.message:
$ref: '#/components/messages/message'
operations:
AUTHORIZATION_REVOCATION.subscribe:
action: send
channel:
$ref: '#/channels/AUTHORIZATION_REVOCATION'
security:
- type: oauth2
description: The oauth security descriptions
flows:
clientCredentials:
tokenUrl: 'https://example.com/api/oauth/dialog'
availableScopes:
'subscribe:auth_revocations': Scope required for authorization revocation topic
scopes:
- 'subscribe:auth_revocations'
```

The `security` field comprises of 2 parts -

- Security scheme object = This portion mentions the security schemes associated with the given operation. One of the security scheme objects must be satisfied to authorize an operation.

- Reference object = This portion references a definition by linking to somewhere else in the document using the `$ref:` keyword.

## Specifying Security Requirement

To specify different security requirements for a specific operation, you can include the `security` property within the operation's definition.
The security property is an array where you can define one or more security requirement objects.

For example, let's say you have an AsyncAPI document with a channel called users and two operations within that channel: `createUser` and `getUser`.
The server-level security is set to use API key authentication for all operations within all channels.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot enforce as it is not about overriding,

it is like providing alternative for what is already in the server. Of course you can do a server without security, then have different operations and channels on the same server, each operation with different security - still, it is not overriding/enforcing if you know what I mean

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unable to understand how to improve the content as per your suggestions.
could you please attach some examples or maybe give me a bit more info about the same?

Copy link
Collaborator Author

@BhaswatiRoy BhaswatiRoy Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you cannot enforce as it is not about overriding,

it is like providing alternative for what is already in the server. Of course you can do a server without security, then have different operations and channels on the same server, each operation with different security - still, it is not overriding/enforcing if you know what I mean

I have removed the line that stated about enforcing/overriding, though not sure if I still was able to resolved the suggestion.


The following example explains how to include security requirement for operations definition

```yaml
BhaswatiRoy marked this conversation as resolved.
Show resolved Hide resolved
title: User sign up
summary: Action to sign a user up.
description: A longer description
channel:
$ref: '#/channels/userSignup'
action: send
security:
- OAuth2: []
```

In the above example, the `security` property is added under the `getUser` operation, indicating that the OAuth2 security requirement should be applied to that specific operation within the user's channel. The empty array [] signifies that no additional configuration is needed for the OAuth2 security mechanism.

Utilizing the security property at the operation level allows you to deviate from the server-level security settings and define unique security requirements for individual operations within your AsyncAPI document. The capability ensures that you can adequately secure your API operations, even if they require different security measures.