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

BCDA-7529: Remove nonsensitive env variables from ops repos #153

Merged
merged 32 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1ce7596
update gorm and pgx dependencies, add idle connection timeout
alex-dzeda Dec 29, 2023
d47bc3d
update config loading
alex-dzeda Jan 8, 2024
36aade2
move imports to systems.go
alex-dzeda Jan 8, 2024
dce2808
remove forced deployment_target of test in docker-compose.test.yml
alex-dzeda Jan 8, 2024
58ebf79
re-add deployment_target in docker-compose.test.yml
alex-dzeda Jan 8, 2024
5cf670b
re-add deployment_target in docker-compose.test.yml
alex-dzeda Jan 8, 2024
6bb7d01
add exit message
alex-dzeda Jan 9, 2024
ae2d948
remove duplicate panic
alex-dzeda Jan 9, 2024
a5482d1
remove unreachable line
alex-dzeda Jan 9, 2024
aa3d37e
pass unit test on required var
alex-dzeda Jan 9, 2024
6a92bed
update description for failure to load
alex-dzeda Jan 9, 2024
c6311b9
update description for failure to load
alex-dzeda Jan 9, 2024
34549f7
update volumes
alex-dzeda Jan 9, 2024
05ddf2d
update description for failure to load
alex-dzeda Jan 9, 2024
784c1a4
set default gopath
alex-dzeda Jan 9, 2024
9e51588
add additional debug messages
alex-dzeda Jan 9, 2024
c9d9557
copy config file
alex-dzeda Jan 9, 2024
d8aa91a
update directory
alex-dzeda Jan 9, 2024
8b5816d
re-configure relative path for file
alex-dzeda Jan 10, 2024
3ba7761
add additional test
alex-dzeda Jan 10, 2024
8f969eb
add gopath/goroot addition
alex-dzeda Jan 10, 2024
7a0de7a
add logging for directories
alex-dzeda Jan 10, 2024
afe7ca7
add printouts for walking
alex-dzeda Jan 10, 2024
8201ad9
update log messages to ensure they go to splunk
alex-dzeda Jan 10, 2024
01b40d3
update logger
alex-dzeda Jan 10, 2024
d7d5d26
post all files checked
alex-dzeda Jan 10, 2024
fc01dc4
update build and package
alex-dzeda Jan 10, 2024
ab31982
update build and package
alex-dzeda Jan 10, 2024
0354e92
update packaging
alex-dzeda Jan 10, 2024
72f3244
update relative path
alex-dzeda Jan 10, 2024
6040892
update reference path
alex-dzeda Jan 10, 2024
8ee876f
clean up branch
alex-dzeda Jan 11, 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: 2 additions & 0 deletions Dockerfiles/Dockerfile.ssas
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ RUN go build -ldflags "-X github.com/CMSgov/bcda-ssas-app/ssas/constants.Version
FROM golang:1.19-alpine3.15
RUN apk update upgrade
RUN apk --no-cache add ca-certificates aws-cli curl
WORKDIR /go/src/github.com/CMSgov/bcda-ssas-app
COPY --from=builder /go/src/github.com/CMSgov/bcda-ssas-app/ssas/cfg/configs ssas/cfg/configs
WORKDIR /usr/local/bin
COPY --from=builder /go/src/github.com/CMSgov/bcda-ssas-app/ssas/ssas .
COPY --from=documentation /go/src/github.com/CMSgov/bcda-ssas-app/ssas/swaggerui ./swaggerui
Expand Down
3 changes: 1 addition & 2 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ services:
dockerfile: Dockerfiles/Dockerfile.tests
args:
VERSION: latest
env_file:
- ./ssas/cfg/configs/local.env
environment:
- DB=postgresql://postgres:toor@db:5432
- DATABASE_URL=postgresql://postgres:toor@db:5432/bcda?sslmode=disable
- BCDA_SSAS_CLIENT_ID=fake-client-id
- BCDA_SSAS_SECRET=fake-secret
- DEPLOYMENT_TARGET=local
- SSAS_ADMIN_SIGNING_KEY_PATH=../../../shared_files/ssas/admin_test_signing_key.pem
- SSAS_PUBLIC_SIGNING_KEY_PATH=../../../shared_files/ssas/public_test_signing_key.pem
- SSAS_PUBLIC_PORT=:3003
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ services:
args:
VERSION: latest
image: bcda-ssas:latest
env_file:
- ./ssas/cfg/configs/local.env
environment:
- DATABASE_URL=postgresql://postgres:toor@db:5432/bcda?sslmode=disable
- ATO_PUBLIC_KEY_FILE=../shared_files/ATO_public.pem
Expand All @@ -34,7 +32,6 @@ services:
- BCDA_AUTH_PROVIDER=${BCDA_AUTH_PROVIDER}
- BCDA_SSAS_CLIENT_ID=${BCDA_SSAS_CLIENT_ID}
- BCDA_SSAS_SECRET=${BCDA_SSAS_SECRET}
- DEBUG=true
- DEPLOYMENT_TARGET=local
- SSAS_ADMIN_SIGNING_KEY_PATH=../shared_files/ssas/admin_test_signing_key.pem
- SSAS_PUBLIC_SIGNING_KEY_PATH=../shared_files/ssas/public_test_signing_key.pem
Expand All @@ -50,6 +47,7 @@ services:
- SSAS_CLIENT_ASSERTION_AUD=http://local.testing.cms.gov/api/v2/Token/auth
volumes:
- ./shared_files:/usr/local/shared_files
- .:/go/src/github.com/CMSgov/bcda-ssas-app
ports:
- "3103:3003"
- "3104:3004"
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ require (
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
2 changes: 1 addition & 1 deletion ops/build_and_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ go clean
echo "Building ssas..."
go build -ldflags "-X github.com/CMSgov/bcda-ssas-app/ssas/constants.Version=$VERSION" -o ssas ./service/main
echo "Packaging ssas binary into RPM..."
fpm -v $VERSION -s dir -t rpm -n ssas ssas=/usr/local/bin/ssas swaggerui=/etc/sv/ssas
fpm -v $VERSION -s dir -t rpm -n ssas ssas=/usr/local/bin/ssas swaggerui=/etc/sv/ssas cfg/configs/=/go/src/github.com/CMSgov/bcda-ssas-app/ssas/cfg/configs/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch on this one!



#Sign RPMs
Expand Down
1 change: 1 addition & 0 deletions ssas/cfg/configs/dev.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEBUG=TRUE
DEPLOYMENT_TARGET=dev
SSAS_DEFAULT_SYSTEM_SCOPE=bcda-api
SSAS_IDLE_TIMEOUT=120
Expand Down
1 change: 1 addition & 0 deletions ssas/cfg/configs/local.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEBUG=TRUE
DEPLOYMENT_TARGET=local
SSAS_DEFAULT_SYSTEM_SCOPE=bcda-api
SSAS_IDLE_TIMEOUT=120
Expand Down
1 change: 1 addition & 0 deletions ssas/cfg/configs/opensbx.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEBUG=FALSE
DEPLOYMENT_TARGET=opensbx
SSAS_DEFAULT_SYSTEM_SCOPE=bcda-api
SSAS_IDLE_TIMEOUT=120
Expand Down
1 change: 1 addition & 0 deletions ssas/cfg/configs/prod.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEBUG=FALSE
DEPLOYMENT_TARGET=prod
SSAS_DEFAULT_SYSTEM_SCOPE=bcda-api
SSAS_IDLE_TIMEOUT=120
Expand Down
1 change: 1 addition & 0 deletions ssas/cfg/configs/test.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
DEBUG=FALSE
DEPLOYMENT_TARGET=test
SSAS_DEFAULT_SYSTEM_SCOPE=bcda-api
SSAS_IDLE_TIMEOUT=120
Expand Down
11 changes: 7 additions & 4 deletions ssas/service/main/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
Package main System-to-System Authentication Service

The System-to-System Authentication Service (SSAS) enables one software system to authenticate and authorize another software system. In this model, the Systems act automatically, independent of a human user identity. Human users are involved only to administer the Service, including establishing the identities and privileges of participating systems.

For more details see our repository readme and Postman tests:
- https://github.com/CMSgov/bcda-ssas-app
- https://github.com/CMSgov/bcda-ssas-app/tree/master/test/postman_test

If you have a Client ID and Secret you can use this page to explore the API. To do this, click the green "Authorize" button below and enter your Client ID and secret in the Basic Authentication username and password boxes.
Until you click logout your token will be presented with every request made. To make requests click on the "Try it out" button for the desired endpoint.

Expand All @@ -20,9 +20,11 @@ Until you click logout your token will be presented with every request made. To
SecurityDefinitions:
basic_auth:
type: basic

swagger:meta
*/
//nolint: lll // Ignore long line linting

package main

import (
Expand Down Expand Up @@ -78,6 +80,7 @@ func init() {
if nil != err {
ssas.Logger.Warnf("New Relic integration is disabled: %s", err)
}

}

// We provide some simple commands for bootstrapping the system into place. Commands cannot be combined.
Expand Down
29 changes: 22 additions & 7 deletions ssas/systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"go/build"
"io"
"net"
"os"
Expand All @@ -17,6 +18,7 @@ import (
"time"

"github.com/CMSgov/bcda-ssas-app/ssas/cfg"
"github.com/joho/godotenv"
"github.com/pborman/uuid"
"gorm.io/gorm"
)
Expand All @@ -31,15 +33,28 @@ func init() {
}

func getEnvVars() {
DefaultScope = os.Getenv("SSAS_DEFAULT_SYSTEM_SCOPE")
env := os.Getenv("DEPLOYMENT_TARGET")
gopath := os.Getenv("GOPATH")

if gopath == "" {
gopath = build.Default.GOPATH
//when GOROOT==gopath, it'll still be empty. Thus, we specify what's in our Dockerfile.
if gopath == "" {
gopath = "/go"
}

}

envPath := fmt.Sprintf(gopath+"/src/github.com/CMSgov/bcda-ssas-app/ssas/cfg/configs/%s.env", env)
err := godotenv.Load(envPath)

if err != nil {
ServiceHalted(Event{Help: fmt.Sprintf("Unable to load environment variables in env %s; message: %s", env, err.Error())})
panic("Unable to start application without loading environment variables.")
}
DefaultScope = os.Getenv("SSAS_DEFAULT_SYSTEM_SCOPE")
if DefaultScope == "" {
if os.Getenv("DEBUG") == "true" {
DefaultScope = "bcda-api"
return
}
ServiceHalted(Event{Help: "SSAS_DEFAULT_SYSTEM_SCOPE environment value must be set"})
panic("SSAS_DEFAULT_SYSTEM_SCOPE environment value must be set")
panic("Unable to source default system scope; check env files")
}

expirationDays := cfg.GetEnvInt("SSAS_CRED_EXPIRATION_DAYS", 90)
Expand Down
9 changes: 9 additions & 0 deletions ssas/systems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,15 @@ func (s *SystemsTestSuite) TestScopeEnvSuccess() {
assert.Nil(s.T(), err)
}

func (s *SystemsTestSuite) TestEmptyGoPath() {
err := os.Setenv("GOPATH", "")
if err != nil {
s.FailNow(err.Error())
}
getEnvVars()
assert.Equal(s.T(), "bcda-api", DefaultScope)
}

func (s *SystemsTestSuite) TestScopeEnvDebug() {
getEnvVars()
assert.Equal(s.T(), "bcda-api", DefaultScope)
Expand Down