Skip to content

feat: introduce new container authenticator#140

Merged
padamstx merged 1 commit intomainfrom
container-auth
Aug 10, 2021
Merged

feat: introduce new container authenticator#140
padamstx merged 1 commit intomainfrom
container-auth

Conversation

@padamstx
Copy link
Copy Markdown
Contributor

@padamstx padamstx commented Aug 7, 2021

This commit introduces the new ContainerAuthenticator class,
along with associated tests and documentation.
The ContainerAuthenticator implements the authentication flow
to be used in IKS-managed compute resources where a secure compute resource token
has been injected into the local file system by the IKS compute resource provider.
The authenticator will read the cr token, then use it to obtain an IAM access token
by invoking the IAM "get token" operation with grant-type "cr-token".

Comment thread Authentication.md
# Authentication
The java-sdk-core project supports the following types of authentication:
- Basic Authentication
- Bearer Token
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Some of the changes to this document are to track more closely the Go core version.


// Now add the Content-Type and (optionally) the Authorization header to the token server request.
// Now add the Accept, Content-Type and (optionally) the Authorization header to the token server request.
builder.header(HttpHeaders.ACCEPT, HttpMediaType.APPLICATION_JSON);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I noticed that we weren't previously setting the Accept header on outbound IAM get-token requests, so added that here. Apparently the IAM server doesn't care, but... :)

protected static MockResponse errorResponse(int statusCode) {
return new MockResponse().setResponseCode(statusCode);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a couple of utility methods to this test base class to be used by the authenticator tests.

Map<String, String> env = new HashMap<>();
env.put("SERVICE_1_URL", "https://service1/api");
env.put("SERVICE_1_DISABLE_SSL", "true");
env.put("SERVICE2_URL", "https://service2/api");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just consolidated some auth-related properties with their corresponding service-level properties, organized by service.

Authenticator auth = ConfigBasedAuthenticatorFactory.getAuthenticator("service-1");
assertNotNull(auth);
assertEquals(Authenticator.AUTHTYPE_IAM, auth.authenticationType());
IamAuthenticator iamAuth = (IamAuthenticator) auth;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Noticed that we weren't doing much checking for the IAM and CP4D authenticators here so added some extra validation.

This commit introduces the new ContainerAuthenticator class,
along with associated tests and documentation.
The ContainerAuthenticator implements the authentication flow
to be used in IKS-managed compute resources where a secure compute resource token
has been injected into the local file system by the IKS compute resource provider.
The authenticator will read the cr token, then use it to obtain an IAM access token
by invoking the IAM "get token" operation with grant-type "cr-token".
}
}

// Verify the Authorization header in the specified request builder.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved this to the base class.

@padamstx padamstx self-assigned this Aug 9, 2021
Copy link
Copy Markdown
Contributor

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

@padamstx padamstx merged commit d6b455b into main Aug 10, 2021
@padamstx padamstx deleted the container-auth branch August 10, 2021 17:07
ibm-devx-sdk pushed a commit that referenced this pull request Aug 10, 2021
# [9.12.0](9.11.1...9.12.0) (2021-08-10)

### Features

* introduce new container authenticator ([#140](#140)) ([d6b455b](d6b455b))
@ibm-devx-sdk
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 9.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants