Skip to content

Commit

Permalink
feat: add support for PSC
Browse files Browse the repository at this point in the history
When enabling PSC, all connections will be routed to the PSC endpoint.
  • Loading branch information
enocom committed Apr 16, 2024
1 parent d85cc26 commit a62a0a1
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 66 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,21 @@ jobs:
uses: google-github-actions/get-secretmanager-secrets@61067887622dee4939d68e379b4264a57534fdf6 # v2.1.0
with:
secrets: |-
ALLOYDB_INSTANCE_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_INSTANCE_NAME
ALLOYDB_INSTANCE_URI:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_INSTANCE_NAME
ALLOYDB_CLUSTER_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_CLUSTER_PASS
IMPERSONATED_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/IMPERSONATED_USER
ALLOYDB_IAM_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_PROXY_IAM_USER
ALLOYDB_PSC_INSTANCE_URI:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_PSC_INSTANCE_URI
- name: Run tests
env:
ALLOYDB_DB: 'postgres'
ALLOYDB_USER: 'postgres'
ALLOYDB_PASS: '${{ steps.secrets.outputs.ALLOYDB_CLUSTER_PASS }}'
ALLOYDB_INSTANCE_NAME: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_NAME }}'
ALLOYDB_INSTANCE_URI: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_URI }}'
IMPERSONATED_USER: '${{ steps.secrets.outputs.IMPERSONATED_USER }}'
ALLOYDB_IAM_USER: '${{ steps.secrets.outputs.ALLOYDB_IAM_USER }}'
ALLOYDB_PSC_INSTANCE_URI: '${{ steps.secrets.outputs.ALLOYDB_PSC_INSTANCE_URI }}'
# specifying bash shell ensures a failure in a piped process isn't lost by using `set -eo pipefail`
shell: bash
run: |
Expand Down
7 changes: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,10 @@ status code.`)
"(*) Enables Automatic IAM Authentication for all instances")
localFlags.BoolVar(&c.conf.PublicIP, "public-ip", false,
"(*) Connect to the public ip address for all instances")
localFlags.BoolVar(&c.conf.PSC, "psc", false,
"(*) Connect to the PSC endpoint for all instances")

return c

}

func loadConfig(c *Command, args []string, opts []Option) error {
Expand Down Expand Up @@ -920,6 +921,10 @@ func parseConfig(cmd *Command, conf *proxy.Config, args []string) error {
if err != nil {
return err
}
ic.PSC, err = parseBoolOpt(q, "psc")
if err != nil {
return err
}
}
ics = append(ics, ic)
}
Expand Down
27 changes: 27 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,33 @@ func TestNewCommandArguments(t *testing.T) {
}},
}),
},
{
desc: "PSC",
args: []string{
"--psc",
"projects/proj/locations/region/clusters/clust/instances/inst",
},
want: withDefaults(&proxy.Config{
PSC: true,
Instances: []proxy.InstanceConnConfig{{Name: "projects/proj/locations/region/clusters/clust/instances/inst"}},
}),
},
{
desc: "PSC query param (true & false)",
args: []string{
"projects/proj/locations/region/clusters/clust/instances/inst1?psc=true",
"projects/proj/locations/region/clusters/clust/instances/inst2?psc=false",
},
want: withDefaults(&proxy.Config{
Instances: []proxy.InstanceConnConfig{{
PSC: pointer(true),
Name: "projects/proj/locations/region/clusters/clust/instances/inst1",
}, {
PSC: pointer(false),
Name: "projects/proj/locations/region/clusters/clust/instances/inst2",
}},
}),
},
{
desc: "using the address flag",
args: []string{"--address", "0.0.0.0", "projects/proj/locations/region/clusters/clust/instances/inst"},
Expand Down
27 changes: 13 additions & 14 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/GoogleCloudPlatform/alloydb-auth-proxy
go 1.22

require (
cloud.google.com/go/alloydbconn v1.8.0
cloud.google.com/go/alloydbconn v1.9.0
contrib.go.opencensus.io/exporter/prometheus v0.4.2
contrib.go.opencensus.io/exporter/stackdriver v0.13.14
github.com/coreos/go-systemd/v22 v22.5.0
Expand All @@ -15,15 +15,15 @@ require (
github.com/spf13/viper v1.18.2
go.opencensus.io v0.24.0
go.uber.org/zap v1.27.0
golang.org/x/oauth2 v0.18.0
golang.org/x/sys v0.18.0
google.golang.org/api v0.170.0
golang.org/x/oauth2 v0.19.0
golang.org/x/sys v0.19.0
google.golang.org/api v0.172.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
)

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/alloydb v1.10.0 // indirect
cloud.google.com/go/alloydb v1.10.1 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/longrunning v0.5.5 // indirect
Expand All @@ -40,11 +40,11 @@ require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
Expand Down Expand Up @@ -73,17 +73,16 @@ require (
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240213162025-012b6fc9bca9 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240304161311-37d4d3c04a78 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240311132316-a219d84964c2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
Loading

0 comments on commit a62a0a1

Please sign in to comment.