Skip to content

feat: introduce new container authenticator #140

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

Merged
merged 1 commit into from
Aug 10, 2021
Merged

Conversation

padamstx
Copy link
Member

@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".

@@ -1,9 +1,10 @@
# Authentication
The java-sdk-core project supports the following types of authentication:
- Basic Authentication
- Bearer Token
Copy link
Member 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.

@@ -421,7 +421,8 @@ public IamToken requestToken() {
// Form a POST request to retrieve the access token.
RequestBuilder builder = RequestBuilder.post(RequestBuilder.resolveRequestUrl(this.getURL(), OPERATION_PATH));

// 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
Member 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... :)

@@ -80,4 +91,44 @@ protected static MockResponse jsonResponse(Object body) {
protected static MockResponse errorResponse(int statusCode) {
return new MockResponse().setResponseCode(statusCode);
}

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

@@ -45,37 +50,52 @@
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
Member 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.

@@ -201,6 +278,12 @@ public void testEnvCredentialsService1() {
Authenticator auth = ConfigBasedAuthenticatorFactory.getAuthenticator("service-1");
assertNotNull(auth);
assertEquals(Authenticator.AUTHTYPE_IAM, auth.authenticationType());
IamAuthenticator iamAuth = (IamAuthenticator) 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.

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".
@@ -464,15 +463,6 @@ public void testApiErrorResponse() throws Throwable {
}
}

// Verify the Authorization header in the specified request builder.
Copy link
Member 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
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
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