Skip to content

Fix controller oauth2 support in shared deployments #134

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

Open
wants to merge 2 commits into
base: stage
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion charts/simpipe/templates/deployment-controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ spec:
- name: PROMETHEUS_SERVER_URL
value: {{ .Values.controller.prometheus.serverUrl | quote }}
- name: NODE_ENV
value: development
value: {{ .Values.controller.nodeEnv | quote }}
- name: OAUTH2_ISSUER_ENDPOINT
value: {{ .Values.controller.oauth2.issuerEndpoint | quote }}
ports:
- name: http
containerPort: {{ .Values.controller.service.port }}
Expand Down
3 changes: 3 additions & 0 deletions charts/simpipe/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ controller:
endpoint: http://simpipe-argo-workflows-server:2746/
prometheus:
serverUrl: http://prometheus-operated:9090
nodeEnv: development
oauth2:
issuerEndpoint: ""

serviceAccount:
# Annotations to add to the service account
Expand Down
15 changes: 11 additions & 4 deletions controller/src/server/auth-jwt-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,24 @@ const fixedLocalAuth: Auth = {
async function hybridAuthJwtMiddlewareAsync(
request: Request, response: Response, next: NextFunction,
): Promise<void> {
// Load the Authorisation header
// and that the header is a Bearer token
const authHeader = request.headers.authorization;

// If we are in development mode, we allow a fixed local user
if (oauth2IssuerEndpoint === undefined) {
// Throw an error if the user is trying to use a bearer token
// It might be a dangerous mistake
if (authHeader) {
response.sendStatus(400);
return;
}

(request as unknown as { auth: Auth }).auth = fixedLocalAuth;
next();
return;
}

// Load the Authorisation header
// and that the header is a Bearer token
const authHeader = request.headers.authorization;

// We allow anonymous access to the API
if (!authHeader) {
next();
Expand Down