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

auth: new api auth implementation #36968

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

wbpcode
Copy link
Member

@wbpcode wbpcode commented Nov 4, 2024

Commit Message: auth: new api auth implementation
Additional Description:

To close #34877

Risk Level: low. New extension.
Testing: unit, integration.
Docs Changes: added.
Release Notes: added.
Platform Specific Features: n/a.

Signed-off-by: wangbaiping/wbpcode <wangbaiping@bytedance.com>
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
@wbpcode wbpcode marked this pull request as draft November 4, 2024 16:06
@repokitteh-read-only repokitteh-read-only bot added api deps Approval required for changes to Envoy's external dependencies labels Nov 4, 2024
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).
CC @envoyproxy/dependency-shepherds: Your approval is needed for changes made to (bazel/.*repos.*\.bzl)|(bazel/dependency_imports\.bzl)|(api/bazel/.*\.bzl)|(.*/requirements\.txt)|(.*\.patch).
envoyproxy/dependency-shepherds assignee is @moderation

🐱

Caused by: #36968 was opened by wbpcode.

see: more, trace.

Comment on lines 43 to 56
message Credential {
// The value of the unique API key.
string api_key = 1 [(validate.rules).string = {min_len: 1}];

// The unique id or identity that used to identify the client or consumer.
string client_id = 2 [(validate.rules).string = {min_len: 1}];
}

message Credentials {
repeated Credential entries = 1;
}

// Api credentials used to authenticate the clients.
Credentials credentials = 1 [(udpa.annotations.sensitive) = true];
Copy link
Member Author

Choose a reason for hiding this comment

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

The api key credenticals has clear structure. It would be better to use a typed message rather than DataSource.

It's OK to change the API because the #36709 was just merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, this implies that only an xDS-update will change the credentials.
If that is the intended behavior, that's fine by me, although I can see some (not huge) benefits of using DataSource (e.g., fine-granularity of credentials updates, and using env-vars).

Copy link
Member Author

@wbpcode wbpcode Nov 8, 2024

Choose a reason for hiding this comment

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

@adisuissa Yeah. I know. I prefer the explicitly defined structures rather than plain string or bytes and I think the xDS should be the first way to update the configuration.

And specific to the DataSource advantages, there are two possible compromised ways:

  1. Use the DataSource as config field type but require it's content to keep the structure of the Crendentials. We can load it by the loadFromJsonString directly to a Crendentials proto type.
  2. Add a new DataSource config field in the Credentials future if some users require env/file support. By this way, we can use both xDS or local file/env to configure this filter.

Both are ok to me (and a inclided to the second way), which one would you prefer?

Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
@wbpcode wbpcode removed the deps Approval required for changes to Envoy's external dependencies label Nov 6, 2024
@wbpcode wbpcode marked this pull request as ready for review November 6, 2024 15:24
@repokitteh-read-only repokitteh-read-only bot added the deps Approval required for changes to Envoy's external dependencies label Nov 6, 2024
@wbpcode
Copy link
Member Author

wbpcode commented Nov 6, 2024

cc @envoyproxy/api-shepherds

@wbpcode wbpcode removed the deps Approval required for changes to Envoy's external dependencies label Nov 6, 2024
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
@repokitteh-read-only repokitteh-read-only bot added the deps Approval required for changes to Envoy's external dependencies label Nov 6, 2024
@@ -172,6 +172,7 @@ paths:
- source/extensions/compression/zstd/common/dictionary_manager.h
- source/extensions/filters/http/adaptive_concurrency/controller
- source/extensions/filters/http/admission_control
- source/extensions/filters/http/api_key_auth
Copy link
Member Author

Choose a reason for hiding this comment

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

This is necessary because the ExceptionFreeFactoryBase cannot handle the case where the route specific configuration loading will throw the exception.

Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thanks!
Left a few high-level comments about the API.
I'll review the rest of the code once the API is more stable.

Comment on lines 43 to 56
message Credential {
// The value of the unique API key.
string api_key = 1 [(validate.rules).string = {min_len: 1}];

// The unique id or identity that used to identify the client or consumer.
string client_id = 2 [(validate.rules).string = {min_len: 1}];
}

message Credentials {
repeated Credential entries = 1;
}

// Api credentials used to authenticate the clients.
Credentials credentials = 1 [(udpa.annotations.sensitive) = true];
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, this implies that only an xDS-update will change the credentials.
If that is the intended behavior, that's fine by me, although I can see some (not huge) benefits of using DataSource (e.g., fine-granularity of credentials updates, and using env-vars).

envoy.filters.http.api_key_auth:
categories:
- envoy.filters.http
security_posture: robust_to_untrusted_downstream
Copy link
Contributor

Choose a reason for hiding this comment

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

This will probably need a signoff from the security group.

Copy link
Member Author

Choose a reason for hiding this comment

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

cc @envoyproxy/security-team

source/extensions/filters/http/api_key_auth/api_key_auth.h Outdated Show resolved Hide resolved
wbpcode and others added 2 commits November 8, 2024 09:11
Co-authored-by: Adi (Suissa) Peleg <adip@google.com>
Signed-off-by: code <wbphub@gmail.com>
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
bazel/repositories_extra.bzl Outdated Show resolved Hide resolved
credentials:
entries:
- api_key: one_key
client_id: one_client
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably a dumb question: where does the "one_client" value coming from in the data-plane (how it the "related client" defined)?

Copy link
Member Author

@wbpcode wbpcode Nov 9, 2024

Choose a reason for hiding this comment

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

Probably a dumb question: where does the "one_client" value coming from in the data-plane (how it the "related client" defined)?

It's hard to answer this quesion. the client_id is an identity that related to the key. It could be anything that could be used to identify a client/app or a group of clients/apps.

For a specific example, the gateway production may provides the ability to manage the credentials. And that credentials management module may allow users to create or define the client or consumer, and then, users could create some keys that related to the client/consumer.
In conclusion, it depends on the abstraction of the gateway production.

wbpcode and others added 3 commits November 9, 2024 10:16
Co-authored-by: Adi (Suissa) Peleg <adip@google.com>
Signed-off-by: code <wbphub@gmail.com>
Co-authored-by: Adi (Suissa) Peleg <adip@google.com>
Signed-off-by: code <wbphub@gmail.com>
Co-authored-by: Adi (Suissa) Peleg <adip@google.com>
Signed-off-by: code <wbphub@gmail.com>
@wbpcode
Copy link
Member Author

wbpcode commented Nov 9, 2024

/docs

Copy link

Docs for this Pull Request will be rendered here:

https://storage.googleapis.com/envoy-pr/36968/docs/index.html

The docs are (re-)rendered each time the CI envoy-presubmit (precheck docs) job completes.

🐱

Caused by: a #36968 (comment) was created by @wbpcode.

see: more, trace.

Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
@wbpcode
Copy link
Member Author

wbpcode commented Nov 9, 2024

/retest

Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thanks!
Overall LGTM, mostly left minor comments.
This is now ready for a senior-maintainer pass (preferably someone with the domain background).

@@ -28,27 +26,84 @@ option (xds.annotations.v3.file_status).work_in_progress = true;
// .. code-block:: yaml
//
// authentication_header: "X-API-KEY"
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is the authentication_header config field defined?

Copy link
Member Author

Choose a reason for hiding this comment

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

sorry, this should be updated.

Comment on lines +68 to +69
absl::variant<Http::LowerCaseString, std::string> source_{""};
bool query_source_{};
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a code smell that is due to the use of absl::variant over using OO polymorphism.

wbpcode and others added 3 commits November 13, 2024 11:22
….proto

Co-authored-by: Adi (Suissa) Peleg <adip@google.com>
Signed-off-by: code <wbphub@gmail.com>
….proto

Co-authored-by: Adi (Suissa) Peleg <adip@google.com>
Signed-off-by: code <wbphub@gmail.com>
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
@wbpcode
Copy link
Member Author

wbpcode commented Nov 13, 2024

Hi, @yanavlasov could you take a look at this PR to give second pass when you get some free time. I saw you are maintainer of jwt and rbac, so should have lots of background knowledge about the authentication/authorizaton.

Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api deps Approval required for changes to Envoy's external dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API Key auth
6 participants