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

feat: identity group auth #497

Merged
merged 9 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions src/pepr/operator/controllers/keycloak/client-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@ async function syncClient(
// If an existing client is found, update it
if (token && !isRetry) {
Log.debug(pkg.metadata, `Found existing token for ${clientReq.clientId}`);
handleClientGroups(clientReq);
client = await apiCall(clientReq, "PUT", token);
} else {
Log.debug(pkg.metadata, `Creating new client for ${clientReq.clientId}`);
handleClientGroups(clientReq);
client = await apiCall(clientReq);
}
UnicornChance marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -142,6 +144,18 @@ async function syncClient(
}
}

/**
* Handles the client groups by converting the groups to attributes.
* @param clientReq - The client request object.
*/
function handleClientGroups(clientReq: Sso) {
UnicornChance marked this conversation as resolved.
Show resolved Hide resolved
if (clientReq.groups) {
UnicornChance marked this conversation as resolved.
Show resolved Hide resolved
clientReq.attributes = clientReq.attributes || {};
clientReq.attributes["uds.core.groups"] = JSON.stringify(clientReq.groups);
delete clientReq.groups;
}
}
UnicornChance marked this conversation as resolved.
Show resolved Hide resolved

async function apiCall(sso: Partial<Sso>, method = "POST", authToken = "") {
// Handle single test mode
if (UDSConfig.isSingleTest) {
Expand Down
14 changes: 14 additions & 0 deletions src/pepr/operator/crd/generated/package-v1alpha1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ export interface Sso {
* Whether the SSO client is enabled
*/
enabled?: boolean;
/**
* The client sso group type
*/
groups?: Groups;
/**
* If true, the client will generate a new Auth Service client as well
*/
Expand Down Expand Up @@ -526,6 +530,16 @@ export enum ClientAuthenticatorType {
ClientSecret = "client-secret",
}

/**
* The client sso group type
*/
export interface Groups {
/**
* List of group allowed to access to client
*/
anyOf?: string[];
}

/**
* Specifies the protocol of the client, either 'openid-connect' or 'saml'
*/
Expand Down
13 changes: 13 additions & 0 deletions src/pepr/operator/crd/sources/package/v1alpha1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,19 @@ const sso = {
type: "string",
},
},
groups: {
description: "The client sso group type",
type: "object",
properties: {
anyOf: {
description: "List of group allowed to access to client",
UnicornChance marked this conversation as resolved.
Show resolved Hide resolved
type: "array",
items: {
type: "string",
},
},
},
},
},
} as V1JSONSchemaProps,
} as V1JSONSchemaProps;
Expand Down
Loading