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

Delete stale Cruise Control API users #10787

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
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 @@ -223,7 +223,13 @@ private static String generateApiAuthFileAsString(Map<String, UserEntry> entries
if (secret != null) {
if (secret.getData().containsKey(AUTH_FILE_KEY)) {
String credentialsAsString = Util.decodeFromBase64(secret.getData().get(AUTH_FILE_KEY));
entries.putAll(parseEntriesFromString(credentialsAsString));
for (Map.Entry<String, UserEntry> entry : parseEntriesFromString(credentialsAsString).entrySet()) {
String key = entry.getKey();
UserEntry value = entry.getValue();
if (key.equals(REBALANCE_OPERATOR_USERNAME) || key.equals(HEALTHCHECK_USERNAME)) {
entries.put(key, value);
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,12 @@ public void testGenerateUserManagedApiCredentials() {
public void testGenerateCoManagedApiCredentials() {
PasswordGenerator mockPasswordGenerator = new PasswordGenerator(10, "a", "a");

// Test that credentials from previous secret are reused
// Given an existing cruiseControlApi secret test that CO credentials are reused and user-managed credentials are deleted
Map<String, String> map1 = Map.of("cruise-control.authFile",
encodeToBase64("rebalance-operator: password,ADMIN\n" +
"healthcheck: password,USER"));
"healthcheck: password,USER\n" +
"userOne: passwordOne, USER\n" +
"userTwo: passwordOne, VIEWER"));
Map<String, HashLoginServiceApiCredentials.UserEntry> entries = new HashMap<>();
HashLoginServiceApiCredentials.generateCoManagedApiCredentials(entries, mockPasswordGenerator, createSecret(map1));
assertThat(entries.get("rebalance-operator").username(), is("rebalance-operator"));
Expand All @@ -282,6 +284,10 @@ public void testGenerateCoManagedApiCredentials() {
assertThat(entries.get("healthcheck").password(), is("password"));
assertThat(entries.get("healthcheck").role(), is(HashLoginServiceApiCredentials.Role.USER));

assertThat(entries.size(), is(2));
assertThat(entries.get("userOne"), is(nullValue()));
assertThat(entries.get("userTwo"), is(nullValue()));

// Test malformed secret credentials with blank password for user throws error
final Map<String, String> map2 = Map.of("cruise-control.authFile",
encodeToBase64("rebalance-operator: ,ADMIN\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ spec:
cruiseControl:
# ...
apiUsers:
type: hashloginservice
type: hashLoginService
valueFrom:
secretKeyRef:
name: cruise-control-api-users-secret
Expand Down
Loading