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 Manager API part 5: SigV4 Auth Manager #11995

Merged
merged 4 commits into from
Feb 7, 2025

Conversation

adutra
Copy link
Contributor

@adutra adutra commented Jan 17, 2025

5th PR for the Auth Manager API. Previous ones:

This PR introduces the SigV4 auth manager. It can be reviewed independently of part4.

The peculiarity of the SIgV4 manager is that it takes a delegate auth manager. IOW, it is able to first delegate authentication to some other auth manager (by default, OAuth2), then sign the request, potentially relocating the authorization header introduced by the delegate manager. This is the current behavior of SigV4 signing.

Contrary to what I said earlier on the dev list, the SigV4 manager at this stage is still "unplugged". Merging this PR is completely harmless.

The old RESTSigV4Signer is still there and active, its contents can be compared with those of the new RESTSigV4AuthSession that will replace it soon.

\cc @nastra @danielcweeks

@jbonofre
Copy link
Member

The flink test failure seems unrelated. I will try to trigger a new run.


@Override
public HTTPRequest authenticate(HTTPRequest request) {
return sign(delegate.authenticate(request));
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't appear to have a precondition check or protect against the delegate being null.

@danielcweeks
Copy link
Contributor

Only one minor comment, but I'll wait for @nastra to look this over as well.

@adutra adutra force-pushed the auth-manager-5-final branch from d48a965 to 5de163d Compare February 6, 2025 18:37
@Override
public RESTSigV4AuthSession catalogSession(
RESTClient sharedClient, Map<String, String> properties) {
catalogProperties = properties;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
catalogProperties = properties;
this.catalogProperties = properties;

private final Aws4Signer signer = Aws4Signer.create();
private final AuthManager delegate;

private Map<String, String> catalogProperties;
Copy link
Contributor

Choose a reason for hiding this comment

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

should this maybe be an empty map by default? What happens if the methods are called in the wrong order and the map hasn't been initialized yet?

this.delegate = Preconditions.checkNotNull(delegateAuthSession, "Invalid delegate: null");
this.signingRegion = awsProperties.restSigningRegion();
this.signingName = awsProperties.restSigningName();
this.credentialsProvider = awsProperties.restCredentialsProvider();
Copy link
Contributor

Choose a reason for hiding this comment

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

is the credentials provider returned here always non-null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking at AwsProperties, yes.

HTTPHeader.of("Content-Type", "application/json"),
HTTPHeader.of("Content-Encoding", "gzip")))
.build());
try (RESTSigV4AuthSession session = new RESTSigV4AuthSession(signer, delegate, awsProperties)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should also have some separate test method(s) that pass nulls as parameters but also where the required aws props (region/name) aren't set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added tests for null parameters but I don't see how to test missing props, because AwsProperties falls back to environment variables in that case.

private Map<String, String> catalogProperties;

public RESTSigV4AuthManager(String name, AuthManager delegate) {
this.delegate = delegate;
Copy link
Contributor

Choose a reason for hiding this comment

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

we might also want to make sure that the delegate is non-null here

@nastra nastra merged commit a89f1f9 into apache:main Feb 7, 2025
46 checks passed
@adutra adutra deleted the auth-manager-5-final branch February 7, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants