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

Support OAuth Token for Kubernetes Authentication via Credential Service #1038

Merged
merged 12 commits into from
Oct 24, 2024

Conversation

minwoox
Copy link
Contributor

@minwoox minwoox commented Sep 26, 2024

Motivation:
The current approach stores the Kubernetes oauthToken in the Kubernetes configuration, which is not ideal for sensitive information. To improve security, we need a way to specify and manage the oauthToken through the credential service, allowing it to be securely retrieved and used by the Kubernetes service.

Modifications:

  • Added functionality to use the oauthToken for Kubernetes authentication via the credential service if the token is specified with credential:.

Result:

  • Kubernetes OAuth tokens can now be securely managed and retrieved through the credential service.

Motivation:
We decided to repurpose the `MirrorCredential` to manage all repository credentials, not just those specific to mirroring. To reflect this role, we should remove `Mirror` prefix from the class name.

Caveat: This commit must be deployed to central dogma replicas after applying the changed from line#1030.

Modifications:
- Renamed `MirroringCredential` to `Credential` and moved its package.
- Removed `hostnamePatterns` property in `Credential`.

Result:
- The renamed `Credential` class can now be used for managing various types of repository credentials, beyond just mirroring.
Motivation:
The current approach stores the Kubernetes oauthToken in the Kubernetes configuration, which is not ideal for sensitive information. To improve security, we need a way to specify and manage the oauthToken through the credential service, allowing it to be securely retrieved and used by the Kubernetes service.

Modifications:
- Added functionality to use the `oauthToken` for Kubernetes authentication via the credential service if the token is specified with `credential:`.

Result:
- Kubernetes OAuth tokens can now be securely managed and retrieved through the credential service.
@jrhee17
Copy link
Contributor

jrhee17 commented Sep 26, 2024

Let me wait until this is rebased over #1031 since it is difficult to review the changes related to OAuth Token.

@minwoox
Copy link
Contributor Author

minwoox commented Sep 26, 2024

Let me wait until this is rebased over #1031 since it is difficult to review the changes related to OAuth Token.

Yeah, let me ping you when it's ready. 😉

@minwoox minwoox added this to the 0.71.0 milestone Sep 27, 2024
@minwoox
Copy link
Contributor Author

minwoox commented Sep 27, 2024

@jrhee17, @ikhoon this is now ready. 😉

if (endpoints.isEmpty()) {
return;
}
executorService.execute(updater::maybeSchedule);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about passing kubernetesEndpointGroup as an argument to maybeSchedule to avoid calling kubernetesEndpointGroupFuture.join()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good suggestion. 👍

}

return configBuilder.build();
if (!oauthToken.startsWith("credential:")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Question) Would it make more sense to enforce users to use credentials?

Since we're still free to make breaking changes, we could just rename oauthToken to credentialId or oauthCredentialId while we're at it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's a good idea. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed. 😉

Copy link
Contributor

@ikhoon ikhoon 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!

if (scheduledFuture != null) {
return;
}
// Commit after 1 second so that it pushes with all the fetched endpoints in the duration
// instead of pushing one by one.
scheduledFuture = executorService.schedule(() -> {
scheduledFuture = null;
// maybeSchedule() is called after the future is completed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be removed?

Status.INTERNAL.withDescription(
"Failed to retrieve k8s endpoints within 5 seconds. watcherName: " +
watcher.getName()).asRuntimeException());
}, 5, TimeUnit.SECONDS);
Copy link
Contributor

Choose a reason for hiding this comment

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

Q) 5 seconds seems short compared to request timeouts. Why did you set 5 seconds as the deadline?

Copy link
Contributor Author

@minwoox minwoox Oct 14, 2024

Choose a reason for hiding this comment

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

I chose a value of less than 10 seconds, which is the request timeout.
This API has two phases: calling k8s and committing.
I estimated that the API would need at least 5 seconds for the committing phase so I allocated 5 seconds for the k8s.
I could potentially increase the default timeout and assign the larger value but I felt it wasn't necessary at this point.
This timeout will also be removed when I implement an API to fetch the information from k8s instead of using k8sEndpointGroup.
Do you have any recommendations?

@minwoox
Copy link
Contributor Author

minwoox commented Oct 24, 2024

Let me merge this to work on supporting merging multiple k8s clusters into one. Thanks!

@minwoox minwoox merged commit 7f6a1bd into line:main Oct 24, 2024
9 of 10 checks passed
@minwoox minwoox deleted the use_credential branch October 24, 2024 12:13
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.

3 participants