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

Local Settings for Cert Setup for Review #653

Merged
merged 2 commits into from
May 8, 2024
Merged
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ AUTH_ECAS_USERINFO="ECAS userinfo endpoint"
AUTH_PRIVATE={ "kty": "RSA", "n": "example private key" }
AUTH_DISABLED="set to 'true' to disable authentiation"
SWAP_USER_TESTING_LINKS = "Set true to use UT links"
MSCA_NG_CERT_LOCATION="./env.crt"

# OpenTelemetry/Dynatrace settings
# Note: to disable metrics and/or tracing exporting, leave the respective endpoint undefined
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ yarn-error.log*
.env
.env.local

#cert
env.crt

# typescript
*.tsbuildinfo
next-env.d.ts
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ ARG user=nodeuser
ARG group=nodegroup
ARG home=/srv/app

ARG MSCA_NG_CERT_LOCATION=/usr/local/share/ca-certificates/env.crt
ENV MSCA_NG_CERT_LOCATION=$MSCA_NG_CERT_LOCATION

RUN addgroup \
-S ${group} \
--gid 1001 && \
Expand All @@ -48,7 +51,7 @@ RUN addgroup \

WORKDIR ${home}

COPY --from=build --chown=${user}:${group} /usr/local/share/ca-certificates/env.crt /usr/local/share/ca-certificates/env.crt
COPY --from=build --chown=${user}:${group} /usr/local/share/ca-certificates/env.crt ${MSCA_NG_CERT_LOCATION}

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* && update-ca-certificates

Expand Down
14 changes: 11 additions & 3 deletions pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ async function decryptJwe(jwe: string, jwk: any) {
return jose.decodeJwt(decryptResult.plaintext.toString())
}

//Create httpsAgent to read in cert to make BRZ call
const httpsAgent =
process.env.AUTH_DISABLED === 'true'
? new https.Agent()
: new https.Agent({
ca: fs.readFileSync(
process.env.MSCA_NG_CERT_LOCATION as fs.PathOrFileDescriptor,
),
})

export const authOptions: NextAuthOptions = {
providers: [
{
Expand Down Expand Up @@ -103,9 +113,7 @@ export const authOptions: NextAuthOptions = {
'authorization': `Basic ${process.env.MSCA_NG_CREDS}`,
'Content-Type': 'application/json',
},
httpsAgent: new https.Agent({
ca: fs.readFileSync('/usr/local/share/ca-certificates/env.crt'),
}),
httpsAgent: httpsAgent,
},
)
.then((response) => response)
Expand Down
Loading