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

ASCN-234: Add support for oidc/okta configuration #5

Merged
merged 28 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
aaab213
Configure okta
stephen-vakil Jul 18, 2024
03f39a3
Merge branch 'main' into ASCN-234
stephen-vakil Jul 18, 2024
52fba34
Fixes for charts relating to the new secrets
stephen-vakil Jul 18, 2024
fcc2d5c
Refactor security provider chart settings
stephen-vakil Jul 18, 2024
b364fb0
Check for null in opserverSettings.security before evaluating
stephen-vakil Jul 18, 2024
37b2015
revert previous change; fix values property name
stephen-vakil Jul 18, 2024
17abb2f
Add flag to always use https in oidc referral
stephen-vakil Jul 18, 2024
6f70eaa
Always use https for scheme
stephen-vakil Jul 18, 2024
9633c1a
Add logging statements (to remove later)
stephen-vakil Jul 18, 2024
d397918
Refactor redirecturi to a method used in both places
stephen-vakil Jul 18, 2024
0a3719d
Change redirect uri method to be sync
stephen-vakil Jul 18, 2024
aa2a65e
Remove unused variable
stephen-vakil Jul 19, 2024
7d947d5
Add redirect URI to callback error
stephen-vakil Jul 19, 2024
5317cd9
Fix typo in variable name
stephen-vakil Jul 19, 2024
d5e2234
Add logging of user details in NoConfig view
stephen-vakil Jul 19, 2024
f23510c
Use correct class name in razor
stephen-vakil Jul 19, 2024
34d18be
Add logging in a few places to troubleshoot
stephen-vakil Jul 19, 2024
20e83e8
Various fixes caused by me refusing to compile before comitting
stephen-vakil Jul 19, 2024
91d7ad3
Log all user groups each time we check membership
stephen-vakil Jul 19, 2024
5c1bcbb
More debugging logs in group checks
stephen-vakil Jul 19, 2024
81db36e
Fix handling of array for groups in chart
stephen-vakil Jul 19, 2024
5a6337a
Fix chart variable reference
stephen-vakil Jul 19, 2024
0329c8d
Revert array stuff because it's semicolon-separated single string value
stephen-vakil Jul 19, 2024
f3db0ee
Set default db to master cuz nothing else makes sense
stephen-vakil Jul 19, 2024
c24d367
fix whitespace issue in chart
stephen-vakil Jul 19, 2024
cd7fd99
Clean up all the logging
stephen-vakil Jul 19, 2024
a7df2be
Move default connection string outside range
stephen-vakil Jul 19, 2024
5738c4b
Remove redundant values that mirror values.yaml
stephen-vakil Jul 22, 2024
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
2 changes: 1 addition & 1 deletion charts/opserver/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.1
version: 1.0.13

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
41 changes: 40 additions & 1 deletion charts/opserver/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,49 @@ spec:
secretKeyRef:
name: {{ .Values.sqlExternalSecret.targetName }}
key: exceptionalPassword
- name: Security__Provider
value: {{ .Values.opserverSettings.security.provider }}

{{- if eq .Values.opserverSettings.security.provider "OIDC" }}
- name: Security__UseHttpsForRedirects
value: "true"
- name: Security__Name
value: "Okta"
- name: Security__ViewEverythingGroups
value: {{ .Values.opserverSettings.security.viewGroups | quote }}
- name: Security__AdminEverythingGroups
value: {{ .Values.opserverSettings.security.adminGroups | quote }}
- name: Security__ClientId
valueFrom:
secretKeyRef:
name: {{ .Values.opserverExternalSecret.targetName }}
key: oktaClientId
- name: Security__ClientSecret
valueFrom:
secretKeyRef:
name: {{ .Values.opserverExternalSecret.targetName }}
key: oktaClientSecret
- name: Security__AuthorizationUrl
value: "https://stackoverflow.okta.com/oauth2/v1/authorize"
- name: Security__AccessTokenUrl
value: "https://stackoverflow.okta.com/oauth2/v1/token"
- name: Security__UserInfoUrl
value: "https://stackoverflow.okta.com/oauth2/v1/userinfo"
- name: Security__NameClaim
value: "preferred_username"
- name: Security__GroupsClaim
value: "groups"
- name: Security__Scopes__0
value: "email"
- name: Security__Scopes__1
value: "groups"
- name: Security__Scopes__2
value: "profile"
{{- end }}

{{- if hasKey .Values.opserverSettings "sql" }}
- name: Modules__Sql__defaultConnectionString
value: "Server=$(SQL_EXCEPTIONAL_SERVERNAME);Database=Local.Exceptions;User ID=$(SQL_USERNAME);Password=$(SQL_PASSWORD);"
value: "Server=$(SQL_EXCEPTIONAL_SERVERNAME);Database=master;User ID=$(SQL_USERNAME);Password=$(SQL_PASSWORD);"
WouterDeKort marked this conversation as resolved.
Show resolved Hide resolved
{{- range $i, $instance := .Values.opserverSettings.sql }}
- name: Modules__Sql__instances__{{ $i }}__name
value: "{{ $instance.name }}"
Expand Down
18 changes: 18 additions & 0 deletions charts/opserver/templates/opserver-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: external-secrets.io/v1beta1
kind: ExternalSecret
metadata:
name: {{ .Values.opserverExternalSecret.name }}
spec:
refreshInterval: {{ .Values.opserverExternalSecret.refreshInterval }}
secretStoreRef:
name: {{ .Values.opserverExternalSecret.storeRefName }}
kind: ClusterSecretStore
target:
name: {{ .Values.opserverExternalSecret.targetName }}
data:
- secretKey: oktaClientId
WouterDeKort marked this conversation as resolved.
Show resolved Hide resolved
remoteRef:
key: {{ .Values.opserverExternalSecret.remoteRefs.oktaClientId }}
- secretKey: oktaClientSecret
remoteRef:
key: {{ .Values.opserverExternalSecret.remoteRefs.oktaClientSecret }}
9 changes: 9 additions & 0 deletions charts/opserver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ ingress:
db:
ExceptionalDbName: Local.Exceptions

opserverExternalSecret:
name: opserver-secret
refreshInterval: 5m
storeRefName: fakeopserversecretstore
targetName: opserver-secret
remoteRefs:
oktaClientId: opserver-okta-client-id
oktaClientSecret: opserver-okta-client-secret

sqlExternalSecret:
name: opserver-sqldb-external-secret
refreshInterval: 5m
Expand Down
11 changes: 11 additions & 0 deletions cnab/app/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ switch ($action) {
}
}

opserverExternalSecret = @{
name = "opserver-external-secret"
WouterDeKort marked this conversation as resolved.
Show resolved Hide resolved
refreshInterval = "5m"
storeRefName = $vars.vars.secretStore
targetName = "opserver-secret"
remoteRefs = @{
oktaClientId = "opserver-okta-client-id"
oktaClientSecret = "opserver-okta-client-secret"
}
}

opserverSettings = $vars.vars.opserverSettings

adminRolebindingGroupId = $vars.vars.adminRolebindingGroupId
Expand Down
16 changes: 11 additions & 5 deletions cnab/app/variables.GCP.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"product": "pubplat",
"project": "opserver",
"tenant": "sandbox",
"releaseTag": "pr-250"
"releaseTag": "pr-5"
},
"runtime": {
"cd": false,
"local": true,
"local": false,
"name": "GCP"
},
"tenant_metadata": {
Expand All @@ -33,12 +33,18 @@
"isHADRPrimary": "true",
"podDisruptionBudgetMinAvailable": "1",
"opserverSettings": {
"hostUrl": "opserver.sandbox.int.gcp.stackoverflow.net",
"sql": [
{ "name": "host.docker.internal" }
{ "name": "db.db" }
],
"exceptions": [
{ "serverName": "host.docker.internal" }
]
{ "serverName": "db.db", "database": "Dev.Exceptions" }
],
"security": {
"adminGroups": "OpserverDev-Admin",
"viewGroups": "OpserverDev-View",
"provider": "OIDC"
}
}
}
}
33 changes: 17 additions & 16 deletions src/Opserver.Web/Controllers/AuthController.OIDC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ partial class AuthController
private const string OidcIdentifierKey = "id";
private const string OidcReturnUrlKey = "returnUrl";

private string GetRedirectUri()
{
var oidcSettings = (OIDCSecuritySettings) Current.Security.Settings;
var scheme = (oidcSettings.UseHttpsForRedirects ? "https" : Request.Scheme);
var redirectUri = Url.Action(
nameof(OAuthCallback),
ControllerContext.ActionDescriptor.ControllerName,
null,
scheme,
Request.Host.Value,
null
);
return redirectUri;
}

[AllowAnonymous]
[HttpGet("login/oauth/callback")]
public async Task<IActionResult> OAuthCallback(string code, string state, string error = null)
Expand Down Expand Up @@ -74,14 +89,7 @@ public async Task<IActionResult> OAuthCallback(string code, string state, string
// hooray! we're all set, let's go fetch our access token
var oidcSettings = (OIDCSecuritySettings) Current.Security.Settings;
var scopes = oidcSettings.Scopes ?? OIDCSecuritySettings.DefaultScopes;
var redirectUri = Url.Action(
nameof(OAuthCallback),
ControllerContext.ActionDescriptor.ControllerName,
null,
Request.Scheme,
Request.Host.Value,
null
);
var redirectUri = GetRedirectUri();

var form = new NameValueCollection
{
Expand Down Expand Up @@ -216,14 +224,7 @@ private IActionResult RedirectToProvider(string returnUrl)
});

var oidcSettings = (OIDCSecuritySettings) Current.Security.Settings;
var redirectUri = Url.Action(
nameof(OAuthCallback),
ControllerContext.ActionDescriptor.ControllerName,
null,
Request.Scheme,
Request.Host.Value,
null
);
var redirectUri = GetRedirectUri();

// construct the URL to the authorization endpoint
var authorizationUrl = new UriBuilder(oidcSettings.AuthorizationUrl);
Expand Down
5 changes: 5 additions & 0 deletions src/Opserver.Web/Security/OIDCSecuritySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@ public class OIDCSecuritySettings : SecuritySettings
/// Gets or sets the name of the "name" claim.
/// </summary>
public string GroupsClaim { get; set; } = "groups";

/// <summary>
/// When redirecting to an OIDC provider, whether to always use https for the redirect/referral.
/// </summary>
public bool UseHttpsForRedirects { get; set; } = false;
}
}
Loading