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

Add ability for BSS to perform client credentials grant for access token #23

Merged
merged 33 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4a14783
Added initial implementation of OAuth registration and token fetch
davidallendj Feb 28, 2024
0265295
Added error checks and access token var
davidallendj Feb 28, 2024
b2d5188
Added AuthorizeClient function to flow
davidallendj Feb 28, 2024
505dc5e
Finalized initial implementation of OAuth client credentials flow
davidallendj Feb 29, 2024
b3a95cf
Add --oauth2-base-url and BSS_OAUTH2_BASE_URL
synackd Feb 29, 2024
de9cc92
Dockerfile: Document BSS_JWKS_URL and BSS_OAUTH2_BASE_URL
synackd Feb 29, 2024
c1ec85f
Merge pull request #1 from synackd/bss-auth-flag-and-env-vars
davidallendj Feb 29, 2024
60e48c7
Move client credentials grant to requestClientCreds()
synackd Feb 29, 2024
b9a225b
OAuth -> OAuth2
synackd Mar 1, 2024
96de4d3
Differentiate admin vs. public OAuth2 base URL
synackd Mar 1, 2024
bb35458
requestClientCreds(): Add log and debug messages
synackd Mar 1, 2024
ce3924a
Add Triad license
synackd Mar 1, 2024
c2e022d
Move RequestClientCreds and accessToken to oauth.go
synackd Mar 2, 2024
4414f04
oauth.go: Add JWT validation/polling functions
synackd Mar 2, 2024
34de2a0
sm.go: Add JWT testing functionality (rm from main.go)
synackd Mar 2, 2024
404c805
Use http.MethodXXX instead of "XXX" string
synackd Mar 2, 2024
8f80f0b
oauth.go: Add JWTTestAndRefresh()
synackd Mar 2, 2024
9484b95
sm.go: Remove JWT refresh code in favor of function
synackd Mar 2, 2024
b7bf17e
getStateFromHSM: Implement JWT authentication
synackd Mar 2, 2024
542ebfa
Try multiple times to test SMD auth enablement
synackd Mar 4, 2024
09a6e1c
RequestClientCreds(): fmt.Printf -> log.Printf
synackd Mar 4, 2024
8225a2e
smClient: Change type from *http.Client to *OAuthClient
synackd Mar 4, 2024
f709047
TestSMAuthEnabled: Add log msg for success
synackd Mar 4, 2024
5665c90
Attach JWT getting functions to OAuthClient, use with smClient
synackd Mar 4, 2024
9df675a
Add smClient nil checks in TestSM* functions
synackd Mar 4, 2024
c27d985
JWTIsValid(): Add debug statements for checking JWT validity date range
synackd Mar 4, 2024
d9b3d75
getStateFromHSM(): Fix wrong error variable (rerr/err)
synackd Mar 4, 2024
5ed2c3d
getStateFromHSM(): Debug responses
synackd Mar 4, 2024
3e22839
Remove printing of access token in logs
synackd Mar 7, 2024
9353c0c
Correct BSS_OAUTH2_USER_BASE_URL IP comment in Dockerfile
synackd Mar 7, 2024
9cd350a
Update copyright year in oauth.go: 2023 -> 2024
synackd Mar 7, 2024
8f40cfa
Merge pull request #2 from synackd/bss-auth-impl-token
davidallendj Mar 8, 2024
b18d281
Fix Errorf/Printf statements with missing args
synackd Mar 8, 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
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ ENV BSS_HSM_RETRIEVAL_DELAY=10
#
# URL of SPIRE token service (not necessary to run BSS).
# SPIRE_TOKEN_URL=https://spire-tokens.spire:54440
#
# URL of JSON Web Key Set (JWKS) server to use for verifying JWTs.
# When this is set, JWT authentication is enabled. Otherwise, it
# is disabled.
# BSS_JWKS_URL=""
#
# Base URL of the Oauth2 server admin endpoints to use for client authorizations
# when JWT authentication is enabled. This is used to authorize BSS via a client
# credentials grant to be able to communicate with protected SMD endpoints when
# it is queried for a boot script.
# BSS_OAUTH2_ADMIN_BASE_URL=http://127.0.0.1:4445
#
# Base URL of the OAuth2 server public endpoints to use for non-admin requests
# like a client (e.g. BSS) requesting an access token after it has been
# authorized.
# BSS_OAUTH2_USER_BASE_URL=http://127.0.0.1:4444

# Etcd variables with default values:
#
Expand Down
59 changes: 40 additions & 19 deletions cmd/boot-script-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ import (
"github.com/OpenCHAMI/bss/internal/postgres"
)

const kvDefaultRetryCount uint64 = 10
const kvDefaultRetryWait uint64 = 5
const sqlDefaultRetryCount uint64 = 10
const sqlDefaultRetryWait uint64 = 5
const authDefaultRetryCount uint64 = 10
const (
kvDefaultRetryCount uint64 = 10
kvDefaultRetryWait uint64 = 5
sqlDefaultRetryCount uint64 = 10
sqlDefaultRetryWait uint64 = 5
authDefaultRetryCount uint64 = 10
authDefaultRetryWait uint64 = 5
)

var (
httpListen = ":27778"
Expand All @@ -84,20 +87,23 @@ var (
// TODO: Set the default to a well known link local address when we have it.
// This will also mean we change the virtual service into an Ingress with
// this well known IP.
advertiseAddress = "" // i.e. http://{IP to reach this service}
insecure = false
debugFlag = false
kvstore hmetcd.Kvi
retryDelay = uint(30)
hsmRetrievalDelay = uint(10)
sqlRetryCount = sqlDefaultRetryCount
sqlRetryWait = sqlDefaultRetryWait
notifier *ScnNotifier
useSQL = false // Use ETCD by default
authRetryCount = authDefaultRetryCount
jwksURL = ""
sqlDbOpts = ""
spireServiceURL = "https://spire-tokens.spire:54440"
advertiseAddress = "" // i.e. http://{IP to reach this service}
insecure = false
debugFlag = false
kvstore hmetcd.Kvi
retryDelay = uint(30)
hsmRetrievalDelay = uint(10)
sqlRetryCount = sqlDefaultRetryCount
sqlRetryWait = sqlDefaultRetryWait
notifier *ScnNotifier
useSQL = false // Use ETCD by default
authRetryCount = authDefaultRetryCount
authRetryWait = authDefaultRetryWait
jwksURL = ""
sqlDbOpts = ""
spireServiceURL = "https://spire-tokens.spire:54440"
oauth2AdminBaseURL = "http://127.0.0.1:4445"
oauth2PublicBaseURL = "http://127.0.0.1:4444"
)

func parseEnv(evar string, v interface{}) (ret error) {
Expand Down Expand Up @@ -302,10 +308,22 @@ func parseEnvVars() error {
if parseErr != nil {
errList = append(errList, fmt.Errorf("BSS_AUTH_RETRY_COUNT: %q", parseErr))
}
parseErr = parseEnv("BSS_AUTH_RETRY_WAIT", &authRetryWait)
if parseErr != nil {
errList = append(errList, fmt.Errorf("BSS_AUTH_RETRY_WAIT: %q", parseErr))
}
parseErr = parseEnv("BSS_JWKS_URL", &jwksURL)
if parseErr != nil {
errList = append(errList, fmt.Errorf("BSS_JWKS_URL: %q", parseErr))
}
parseErr = parseEnv("BSS_OAUTH2_ADMIN_BASE_URL", &oauth2AdminBaseURL)
if parseErr != nil {
errList = append(errList, fmt.Errorf("BSS_OAUTH2_ADMIN_BASE_URL: %q", parseErr))
}
parseErr = parseEnv("BSS_OAUTH2_PUBLIC_BASE_URL", &oauth2PublicBaseURL)
if parseErr != nil {
errList = append(errList, fmt.Errorf("BSS_OAUTH2_PUBLIC_BASE_URL: %q", parseErr))
}

//
// Etcd environment variables
Expand Down Expand Up @@ -401,13 +419,16 @@ func parseCmdLine() {
flag.StringVar(&sqlUser, "postgres-username", sqlUser, "(BSS_DBUSER) Postgres username")
flag.StringVar(&sqlPass, "postgres-password", sqlPass, "(BSS_DBPASS) Postgres password")
flag.StringVar(&jwksURL, "jwks-url", jwksURL, "(BSS_JWKS_URL) Set the JWKS URL to fetch the public key for authorization (enables authentication)")
flag.StringVar(&oauth2AdminBaseURL, "oauth2-admin-base-url", oauth2AdminBaseURL, "(BSS_OAUTH2_ADMIN_BASE_URL) Base URL of the OAUTH2 server admin endpoints for client authorizations")
flag.StringVar(&oauth2PublicBaseURL, "oauth2-public-base-url", oauth2PublicBaseURL, "(BSS_OAUTH2_PUBLIC_BASE_URL) Base URL of the OAUTH2 server public endpoints (e.g. for token grants)")
flag.BoolVar(&insecure, "insecure", insecure, "(BSS_INSECURE) Don't enforce https certificate security")
flag.BoolVar(&debugFlag, "debug", debugFlag, "(BSS_DEBUG) Enable debug output")
flag.BoolVar(&useSQL, "postgres", useSQL, "(BSS_USESQL) Use Postgres instead of ETCD")
flag.UintVar(&retryDelay, "retry-delay", retryDelay, "(BSS_RETRY_DELAY) Retry delay in seconds")
flag.UintVar(&hsmRetrievalDelay, "hsm-retrieval-delay", hsmRetrievalDelay, "(BSS_HSM_RETRIEVAL_DELAY) SM Retrieval delay in seconds")
flag.UintVar(&sqlPort, "postgres-port", sqlPort, "(BSS_DBPORT) Postgres port")
flag.Uint64Var(&authRetryCount, "auth-retry-count", authRetryCount, "(BSS_AUTH_RETRY_COUNT) Retry fetching JWKS public key set")
flag.Uint64Var(&authRetryWait, "auth-retry-wait", authRetryWait, "(BSS_AUTH_RETRY_WAIT) Interval in seconds between authentication request attempts")
flag.Uint64Var(&sqlRetryCount, "postgres-retry-count", sqlRetryCount, "(BSS_SQL_RETRY_COUNT) Amount of times to retry connecting to Postgres")
flag.Uint64Var(&sqlRetryWait, "postgres-retry-wait", sqlRetryCount, "(BSS_SQL_RETRY_WAIT) Interval in seconds between connection attempts to Postgres")
flag.Parse()
Expand Down
Loading
Loading