Skip to content

Added project id to kubeadmin user for Kubernetes service #10362

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,15 @@ private String[] getServiceUserKeys(KubernetesClusterVO kubernetesCluster) {
if (owner == null || owner.getType() == Account.Type.PROJECT) {
owner = CallContext.current().getCallingAccount();
}
String username = owner.getAccountName() + "-" + KUBEADMIN_ACCOUNT_NAME;
Copy link
Member

Choose a reason for hiding this comment

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

@parkinr
can you explain more ?

  • without this PR, what's the username ?
  • with this PR, what's the username ?

Copy link
Author

Choose a reason for hiding this comment

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

Without this PR, the username is: flexcloud-admin-account-kubeadmin
With this PR, the username is flexcloud-admin-account-f316789i-2bgg-4r87-95h7-58j5327892ef-kubeadmin with sample projectId=f316789i-2bgg-4r87-95h7-58j5327892ef. And you can see this projectId in cloudstack-secret on the Kubernetes cluster.

Copy link
Member

Choose a reason for hiding this comment

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

thanks @parkinr for the reply.
However, the security issue is not resolved I think.

@DaanHoogland
we may need to treat this as a serious security issue.


String projectId = "default";
Account account = ApiDBUtils.findAccountById(kubernetesCluster.getAccountId());
Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
if ( project != null ) {
projectId = project.getUuid();
}

String username = owner.getAccountName() + "-" + projectId + "-" + KUBEADMIN_ACCOUNT_NAME;
Comment on lines +1388 to +1395
Copy link
Contributor

Choose a reason for hiding this comment

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

does this mean accounts cannot have a kubernetes instance without being part of a project? I would expect something like

Suggested change
String projectId = "default";
Account account = ApiDBUtils.findAccountById(kubernetesCluster.getAccountId());
Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
if ( project != null ) {
projectId = project.getUuid();
}
String username = owner.getAccountName() + "-" + projectId + "-" + KUBEADMIN_ACCOUNT_NAME;
String projectId = null;
Account account = ApiDBUtils.findAccountById(kubernetesCluster.getAccountId());
Project project = ApiDBUtils.findProjectByProjectAccountId(account.getId());
if ( project != null ) {
projectId = project.getUuid();
}
String username = owner.getAccountName() + (projectId == null ? : "" : "-" + projectId) + "-" + KUBEADMIN_ACCOUNT_NAME;

Copy link
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 idea. Will update the code as such. In our case, we always have projectId.

UserAccount kubeadmin = accountService.getActiveUserAccount(username, owner.getDomainId());
String[] keys = null;
if (kubeadmin == null) {
Expand Down
Loading