Skip to content

auth: new api auth implementation#36968

Merged
wbpcode merged 38 commits intoenvoyproxy:mainfrom
wbpcode:dev-api-auth
Dec 10, 2024
Merged

auth: new api auth implementation#36968
wbpcode merged 38 commits intoenvoyproxy:mainfrom
wbpcode:dev-api-auth

Conversation

@wbpcode
Copy link
Copy Markdown
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.

wangbaiping/wbpcode added 2 commits November 2, 2024 11:06
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
@repokitteh-read-only
Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread api/envoy/extensions/filters/http/api_key_auth/v3/api_key_auth.proto Outdated
wangbaiping(wbpcode) added 2 commits November 6, 2024 15:22
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
Copy Markdown
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
- 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
Copy Markdown
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.

wangbaiping(wbpcode) added 2 commits November 7, 2024 08:47
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Copy link
Copy Markdown
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
Copy Markdown
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).

Comment thread api/envoy/extensions/filters/http/api_key_auth/v3/api_key_auth.proto Outdated
Comment thread api/envoy/extensions/filters/http/api_key_auth/v3/api_key_auth.proto Outdated
Comment thread docs/root/configuration/http/http_filters/api_key_auth_filter.rst Outdated
Comment thread docs/root/configuration/http/http_filters/api_key_auth_filter.rst
Comment thread docs/root/configuration/http/http_filters/api_key_auth_filter.rst
envoy.filters.http.api_key_auth:
categories:
- envoy.filters.http
security_posture: robust_to_untrusted_downstream
Copy link
Copy Markdown
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
Copy Markdown
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Normally for filters which contain parsers and this one does have a small parser, a fuzzer is required to claim the robustness to unstrusted downstream.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am not familiar to the fuzz test. But I add one by refering to jwt fuzz. Hope it make sense.

Comment thread api/envoy/extensions/filters/http/api_key_auth/v3/api_key_auth.proto Outdated
Comment thread source/extensions/filters/http/api_key_auth/api_key_auth.h Outdated
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>
Comment thread docs/root/configuration/http/http_filters/api_key_auth_filter.rst Outdated
@wbpcode
Copy link
Copy Markdown
Member Author

wbpcode commented Nov 19, 2024

wait any basically used to wait author's response. change it to wait review.

Copy link
Copy Markdown
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.

One API question, but otherwise LGTM

// then all authenticated clients are allowed. This provides very limited but simple authorization.
// If more complex authorization is required, then use the :ref:`HTTP RBAC filter
// <config_http_filters_rbac>` instead.
repeated string allowed_clients = 2;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The filter will try to authenticate the client by the override_config (if exists) and filter level configuration first. After the client is authenticated, we will try to check if it's limited by the allowed_clients (if exists and non-empty).

IMHO this is somewhat fragile, and may lead to inconsistencies when new fields are added.
Specifically, IIUC, if both fields are set, the client needs both in the credentials list inside the override_config and in the allowed_clients list.
I understand the motivation behind adding one of the fields, but I'm not sure I fully grok when would adding both fields be useful.
To be more concrete, looking at the example below, it is unclear to me why the {one_key, one_client} pair is useful in the override config (other than maybe receiving a different HTTP response code).

Comment thread api/envoy/extensions/filters/http/api_key_auth/v3/api_key_auth.proto Outdated
Comment thread api/envoy/extensions/filters/http/api_key_auth/v3/api_key_auth.proto Outdated
wbpcode and others added 3 commits November 19, 2024 22:03
….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>
Comment thread api/envoy/extensions/filters/http/api_key_auth/v3/api_key_auth.proto Outdated
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
@wbpcode
Copy link
Copy Markdown
Member Author

wbpcode commented Nov 19, 2024

/retest

@wbpcode wbpcode removed the wait:review Waiting for (further) review label Nov 22, 2024
wangbaiping(wbpcode) added 2 commits November 23, 2024 08:44
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
@wbpcode
Copy link
Copy Markdown
Member Author

wbpcode commented Nov 23, 2024

cc @adisuissa , Hi, adi, the comments are updated and could you take a look at this again? Thanks. 🙏

@yanavlasov
Copy link
Copy Markdown
Contributor

Waiting for @adisuissa review
/wait-any

Comment on lines +46 to +51
// Route specific APIKeyAuth configuration. This is optional and could be used to **override** the
// filter level ApiKeyAuth configuration **partly**.
//
// For example, if non-empty ``credentials`` is set in the ``override_config``, then the
// ``credentials`` in the filter level configuration will be ignored and the ``credentials`` in
// this configuration will be used.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think partial override is the right way to go. If a message of type ApiKeyAuth is provided, then it should replace the one define above entirely. The reason I'm against this is that if a new field is added in the future to ApiKeyAuth where it won't make sense to do a partial override, this will complicate the use of this field and the override.

If an override to a specific field is desired, then an additional field can be added to ApiKeyAuthPerRoute. For example repeated Credential credentials that will override only the credentials defined above.

Copy link
Copy Markdown
Member Author

@wbpcode wbpcode Nov 26, 2024

Choose a reason for hiding this comment

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

If an override to a specific field is desired, then an additional field can be added to ApiKeyAuthPerRoute. For example repeated Credential credentials that will override only the credentials defined above.

Yeah, it's required.

Then I think I can remove the override_config and use the repeated Credential credentials and repeated KeySource key_sources directly.

Comment on lines +60 to +63
// .. note::
// Setting this field and ``override_config.credentials`` at the same configuration entry is not
// an error but also makes no sense because they provide similar functionality. Please only use
// one of them at same configuration entry.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why wouldn't this be an error?
IIUC all the options here are essentially a oneof. As this is a newly introduced feature I think it can either reject or declare the order (prioritization) of these fields.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The authentication and authorization are two different phases. Even both credentials and allowed_clients are configured, the filter could handle them correctly as expected.

So, I don't think this is an error and don't deserve a configuration rejection. The prioritization also only make the implementation more complex and make no much sense.

wangbaiping(wbpcode) added 2 commits November 26, 2024 09:01
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Signed-off-by: wangbaiping(wbpcode) <wangbaiping@bytedance.com>
Copy link
Copy Markdown
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 minor API rephrase suggestion, but otherwise LGTM.

Comment thread api/envoy/extensions/filters/http/api_key_auth/v3/api_key_auth.proto Outdated
Comment thread api/envoy/extensions/filters/http/api_key_auth/v3/api_key_auth.proto Outdated
@yanavlasov
Copy link
Copy Markdown
Contributor

/wait

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>
Copy link
Copy Markdown
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.

/lgtm api

@wbpcode
Copy link
Copy Markdown
Member Author

wbpcode commented Nov 27, 2024

@yanavlasov I think now this is ready for a final review or approval, thanks :)

Copy link
Copy Markdown
Contributor

@yanavlasov yanavlasov left a comment

Choose a reason for hiding this comment

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

LGTM

return ApiKeyAuthStats{ALL_API_KEY_AUTH_STATS(POOL_COUNTER_PREFIX(scope, prefix))};
}

ApiKeyAuthConfig default_config_;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest being strict about const correctness of the configuration types as they are shared across multiple threads.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let's land this PR first and create a new PR immediately.

@wbpcode wbpcode merged commit d2dbc05 into envoyproxy:main Dec 10, 2024
@wbpcode wbpcode deleted the dev-api-auth branch December 10, 2024 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API Key auth

6 participants