Skip to content

Commit

Permalink
Feature Shared IdP (#641)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Jones <joshua@general-metrics.com>
  • Loading branch information
ikethecoder and Jonesy committed Dec 29, 2022
1 parent d453301 commit 00232e2
Show file tree
Hide file tree
Showing 60 changed files with 1,549 additions and 553 deletions.
16 changes: 13 additions & 3 deletions .github/workflows/ci-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ jobs:
image:
registry: docker.pkg.github.com
repository: bcgov-dss/api-serv-infra/mongodb
tag: 4.4.15-2941ec1e
tag: 5.0-7a639fba
pullPolicy: IfNotPresent
pullSecrets:
- dev-github-read-packages-creds
Expand All @@ -111,7 +111,17 @@ jobs:
rbac:
create: true
strategyType: Recreate
updateStrategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 0
maxUnavailable: 100%
readinessProbe:
timeoutSeconds: 20
livenessProbe:
timeoutSeconds: 20
persistence:
enabled: true
Expand All @@ -134,7 +144,7 @@ jobs:
runAsUser: ${{ secrets.RUNNING_UID_GID }}
' > values.yaml
helm repo add bitnami https://charts.bitnami.com/bitnami
helm upgrade --install proto-asp-${{ steps.set-deploy-id.outputs.DEPLOY_ID }}-db --version 10.31.5 -f values.yaml bitnami/mongodb
helm upgrade --install proto-asp-${{ steps.set-deploy-id.outputs.DEPLOY_ID }}-db --version 12.1.31 -f values.yaml bitnami/mongodb
- name: 'Deploy Backend'
if: github.ref != 'refs/heads/dev'
Expand Down
20 changes: 20 additions & 0 deletions local/db/keystone-init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2326,3 +2326,23 @@ ALTER TABLE public."Activity"
ADD COLUMN "filterKey2" text,
ADD COLUMN "filterKey3" text,
ADD COLUMN "filterKey4" text;

ALTER TABLE public."Metric"
ADD COLUMN "namespace" text;

ALTER TABLE public."CredentialIssuer"
ADD COLUMN "isShared" boolean NOT NULL DEFAULT false,
ADD COLUMN "inheritFrom" integer;

--
-- Name: credentialissuer_inheritfrom_index; Type: INDEX; Schema: public; Owner: keystonejsuser
--

CREATE INDEX credentialissuer_inheritfrom_index ON public."CredentialIssuer" USING btree ("inheritFrom");

--
-- Name: CredentialIssuer credentialissuer_inheritfrom_foreign; Type: FK CONSTRAINT; Schema: public; Owner: keystonejsuser
--

ALTER TABLE ONLY public."CredentialIssuer"
ADD CONSTRAINT credentialissuer_inheritfrom_foreign FOREIGN KEY ("inheritFrom") REFERENCES public."CredentialIssuer"(id);
14 changes: 7 additions & 7 deletions local/feeder-init/init.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash

apk add --no-cache curl
cd /tmp

Expand All @@ -13,20 +12,21 @@ while true; do
curl http://feeder.localtest.me:6000/push -F yaml=@developer-user.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@mark-user.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@platform-authz-profile.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@shared-idp.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@platform-gwa-api.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@organization-unit.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@dataset-gwa.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@product-initializer.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@product-initializer-permission.yaml
# curl http://feeder.localtest.me:6000/push -F yaml=@product-initializer.yaml
# curl http://feeder.localtest.me:6000/push -F yaml=@product-initializer-permission.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@cc-dataset-gwa.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@cc-product-initializer.yaml
# curl http://feeder.localtest.me:6000/push -F yaml=@cc-product-initializer.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@cr-dataset-gwa.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@cr-product-initializer.yaml
# curl http://feeder.localtest.me:6000/push -F yaml=@cr-product-initializer.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@permission-dataset-gwa.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@api-dataset-gwa.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@product-initializer-api.yaml
# curl http://feeder.localtest.me:6000/push -F yaml=@product-initializer-api.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@preview-dataset-gwa.yaml
curl http://feeder.localtest.me:6000/push -F yaml=@preview-product-initializer.yaml
# curl http://feeder.localtest.me:6000/push -F yaml=@preview-product-initializer.yaml
break

else
Expand Down
19 changes: 19 additions & 0 deletions local/feeder-init/shared-idp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
entity: CredentialIssuer
record:
id: 'Sample Shared IdP'
namespace: newplatform
description: 'A Shared IdP for Teams to use'
flow: client-credentials
mode: auto
clientAuthenticator: client-secret
authPlugin: jwt-keycloak
clientRoles: []
availableScopes: []
owner: janis@idir
isShared: true
environmentDetails:
- environment: prod
issuerUrl: http://keycloak.localtest.me:9080/auth/realms/master
clientId: gwa-api
clientRegistration: managed
clientSecret: '18900468-3db1-43f7-a8af-e75f079eb742'
2 changes: 1 addition & 1 deletion local/oauth2-proxy/oauth2-proxy-local.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ skip_jwt_bearer_tokens="false"
set_authorization_header="false"
pass_authorization_header="false"
skip_auth_regex="/login|/health|/public|/docs|/redirect|/_next|/images|/devportal|/manager|/about|/maintenance|/admin/session|/ds/api|/feed/|/signout|^[/]$"
whitelist_domains="*"
whitelist_domains="keycloak.localtest.me:9080"
upstreams=["http://apsportal.localtest.me:3000"]
skip_provider_button='true'
redis_connection_url="redis://redis-master:6379"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

query GetCredentialIssuers {
allCredentialIssuersByNamespace {
id
name
flow
mode
owner {
name
username
email
}
environmentDetails
inheritFrom {
name
}
availableScopes
clientAuthenticator
clientRoles
clientMappers
apiKeyName
resourceType
resourceScopes
resourceAccessScope
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

query GetCredentialIssuers {
allCredentialIssuersByNamespace {
id
name
flow
mode
owner {
name
username
email
}
environmentDetails
inheritFrom {
environmentDetails
}
availableScopes
clientAuthenticator
clientRoles
clientMappers
apiKeyName
resourceType
resourceScopes
resourceAccessScope
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

query SharedIdPPreview($profileName: String) {
sharedIdPs(profileName: $profileName) {
id
name
environmentDetails
}
}
1 change: 1 addition & 0 deletions src/authz/matrix.csv
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ CREDENTIAL ADMIN,,,CredentialIssuer,create,,,,,credential-admin,,,allow,
CREDENTIAL ADMIN,,,CredentialIssuer,read,,,,,credential-admin,,,allow,filterByUserNS
CREDENTIAL ADMIN,,,CredentialIssuer,update,,namespace,,,credential-admin,,,deny,
CREDENTIAL ADMIN,,,CredentialIssuer,,"create,read",namespace,,,credential-admin,,,allow,
CREDENTIAL ADMIN,,sharedIdPs,,,,,,,credential-admin,,,allow,
CREDENTIAL ADMIN,,OwnedCredentialIssuer,,,,,,,credential-admin,,,allow,
CREDENTIAL ADMIN,,allCredentialIssuersByNamespace,,,,,,,credential-admin,,,allow,filterByUserNS
CREDENTIAL ADMIN,,,User,read,,,,,credential-admin,,,allow,
Expand Down
8 changes: 8 additions & 0 deletions src/batch/data-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ const metadata = {
'resourceScopes',
'resourceType',
'resourceAccessScope',
'isShared',
'inheritFrom',
'apiKeyName',
'owner',
],
Expand All @@ -473,9 +475,15 @@ const metadata = {
clientRoles: { name: 'toStringDefaultArray' },
clientMappers: { name: 'toStringDefaultArray' },
environmentDetails: { name: 'toString' },
inheritFrom: {
name: 'connectOne',
list: 'allCredentialIssuers',
refKey: 'name',
},
owner: { name: 'connectOne', list: 'allUsers', refKey: 'username' },
},
validations: {
isShared: { type: 'boolean' },
flow: {
type: 'enum',
values: ['client-credentials'],
Expand Down
1 change: 1 addition & 0 deletions src/batch/feed-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ export const syncRecords = async function (
}
}
if (Object.keys(data).length === 0) {
logger.debug('[%s] [%s] no update', entity, localRecord.id);
return {
status: 200,
result: 'no-change',
Expand Down
8 changes: 6 additions & 2 deletions src/controllers/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ components:
clientRegistration: managed
clientId: a-client-id
clientSecret: a-client-secret
CredentialIssuerRefID:
type: string
UserRefID:
type: string
CredentialIssuer:
Expand Down Expand Up @@ -315,6 +317,8 @@ components:
type: string
resourceAccessScope:
type: string
isShared:
type: boolean
apiKeyName:
type: string
availableScopes:
Expand All @@ -333,6 +337,8 @@ components:
items:
type: string
type: array
inheritFrom:
$ref: '#/components/schemas/CredentialIssuerRefID'
owner:
$ref: '#/components/schemas/UserRefID'
type: object
Expand Down Expand Up @@ -508,8 +514,6 @@ components:
type: string
LegalRefID:
type: string
CredentialIssuerRefID:
type: string
Environment:
properties:
appId:
Expand Down
12 changes: 7 additions & 5 deletions src/controllers/v2/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ const models: TsoaRoute.Models = {
"additionalProperties": false,
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"CredentialIssuerRefID": {
"dataType": "refAlias",
"type": {"dataType":"string","validators":{}},
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"UserRefID": {
"dataType": "refAlias",
"type": {"dataType":"string","validators":{}},
Expand All @@ -204,11 +209,13 @@ const models: TsoaRoute.Models = {
"environmentDetails": {"dataType":"array","array":{"dataType":"refObject","ref":"IssuerEnvironmentConfig"}},
"resourceType": {"dataType":"string"},
"resourceAccessScope": {"dataType":"string"},
"isShared": {"dataType":"boolean"},
"apiKeyName": {"dataType":"string"},
"availableScopes": {"dataType":"array","array":{"dataType":"string"}},
"resourceScopes": {"dataType":"array","array":{"dataType":"string"}},
"clientRoles": {"dataType":"array","array":{"dataType":"string"}},
"clientMappers": {"dataType":"array","array":{"dataType":"string"}},
"inheritFrom": {"ref":"CredentialIssuerRefID"},
"owner": {"ref":"UserRefID"},
},
"additionalProperties": false,
Expand Down Expand Up @@ -326,11 +333,6 @@ const models: TsoaRoute.Models = {
"type": {"dataType":"string","validators":{}},
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"CredentialIssuerRefID": {
"dataType": "refAlias",
"type": {"dataType":"string","validators":{}},
},
// WARNING: This file was auto-generated with tsoa. Please do not modify it. Re-run tsoa to re-generate this file: https://github.com/lukeautry/tsoa
"Environment": {
"dataType": "refObject",
"properties": {
Expand Down
7 changes: 7 additions & 0 deletions src/controllers/v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,13 @@ export interface CredentialIssuer {
environmentDetails?: IssuerEnvironmentConfig[];
resourceType?: string;
resourceAccessScope?: string;
isShared?: boolean;
apiKeyName?: string;
availableScopes?: string[];
resourceScopes?: string[];
clientRoles?: string[];
clientMappers?: string[];
inheritFrom?: CredentialIssuerRefID;
owner?: UserRefID;
}

Expand Down Expand Up @@ -455,8 +457,13 @@ export interface Activity {
refId?: string;
namespace?: string;
blob?: string;
filterKey1?: string;
filterKey2?: string;
filterKey3?: string;
filterKey4?: string;
updatedAt?: DateTime;
createdAt?: DateTime;
context?: any; // toString
actor?: UserRefID;
}

Expand Down
Loading

0 comments on commit 00232e2

Please sign in to comment.