Skip to content

Commit 1a09e20

Browse files
committed
feat: use workload identity federation to gain access to google
1 parent 315e85d commit 1a09e20

File tree

11 files changed

+1730
-91
lines changed

11 files changed

+1730
-91
lines changed

.goreleaser.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ archives:
4444
format_overrides:
4545
- goos: windows
4646
format: zip
47-

README.md

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,32 @@ as locally running the ssosync tool.
7272

7373
### Google
7474

75-
First, you have to setup your API. In the project you want to use go to the [Console](https://console.developers.google.com/apis) and select *API & Services* > *Enable APIs and Services*. Search for *Admin SDK* and *Enable* the API.
75+
First, you have to setup your API. In the project you want to use go to the [Console](https://console.developers.google.com/apis) and select
76+
*API & Services* > *Enable APIs and Services*. Search for *Admin SDK* and *Enable* the API.
7677

77-
You have to perform this [tutorial](https://developers.google.com/admin-sdk/directory/v1/guides/delegation) to create a service account that you use to sync your users. Save the `JSON file` you create during the process and rename it to `credentials.json`.
78+
You have to perform this [tutorial](https://developers.google.com/admin-sdk/directory/v1/guides/delegation) to create a
79+
service account that you use to sync your users. This is the service account that is used to impersonate a user
80+
(via `--google-admin`). You have two possibilities to use this service account. Create a service account key credential,
81+
as describe in the tutorial above. Or use
82+
[Workload Identity Federation](https://cloud.google.com/iam/docs/workload-identity-federation).
83+
84+
#### Service account key credential
85+
86+
Save the `JSON file` you create during the process described in the tutorial above and rename it to `credentials.json`.
87+
Please, keep this file safe, or store it in the AWS Secrets Manager.
88+
89+
#### Workload Identity Federation
90+
91+
Set up Workload Identity Federation for AWS as described
92+
[here](https://cloud.google.com/iam/docs/workload-identity-federation-with-other-clouds) and save the `JSON file`, and
93+
rename it to `credentials.json`. Provide the email address of service account used to impersonate a user using
94+
`--google-service-account-email`.
95+
Note that the `JSON file` created using this approach **does not** contain any sensitive data.
96+
97+
> You can also use the `--google-credentials` parameter to explicitly specify the file containing the credentials.
98+
> Setting this parameter to an empty string will use
99+
> [Application Default Credentials](https://cloud.google.com/docs/authentication/application-default-credentials).
78100
79-
> you can also use the `--google-credentials` parameter to explicitly specify the file with the service credentials. Please, keep this file safe, or store it in the AWS Secrets Manager
80101

81102
In the domain-wide delegation for the Admin API, you have to specify the following scopes for the user.
82103

@@ -89,6 +110,9 @@ In the Search box type `Admin` and select the `Admin SDK` option. Click the `Ena
89110

90111
You will have to specify the email address of an admin via `--google-admin` to assume this users role in the Directory.
91112

113+
> When running this tool as AWS Lambda, the parameter `--google-credentials` is expected to contain the content of the
114+
> `JSON file`.
115+
92116
### AWS
93117

94118
Go to the AWS Single Sign-On console in the region you have set up AWS SSO and select

SAR.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ There are general configuration parameters to the application stack.
2323

2424
* `GoogleCredentials` contains the content of the `credentials.json` file
2525
* `GoogleAdminEmail` contains the email address of an admin
26+
* `GoogleSAEmail` contains the email address of a Google service account used to impersonate the admin user
2627

2728
The secrets are stored in the [AWS Secrets Manager](https://aws.amazon.com/secrets-manager/).
2829

cmd/root.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ import (
2020
"fmt"
2121
"os"
2222

23-
"github.com/awslabs/ssosync/internal"
24-
"github.com/awslabs/ssosync/internal/config"
25-
"github.com/aws/aws-sdk-go/aws"
2623
"github.com/aws/aws-lambda-go/events"
27-
"github.com/aws/aws-sdk-go/service/codepipeline"
2824
"github.com/aws/aws-lambda-go/lambda"
25+
"github.com/aws/aws-sdk-go/aws"
2926
"github.com/aws/aws-sdk-go/aws/session"
27+
"github.com/aws/aws-sdk-go/service/codepipeline"
3028
"github.com/aws/aws-sdk-go/service/secretsmanager"
29+
"github.com/awslabs/ssosync/internal"
30+
"github.com/awslabs/ssosync/internal/config"
3131
"github.com/pkg/errors"
3232
log "github.com/sirupsen/logrus"
3333
"github.com/spf13/cobra"
@@ -157,6 +157,7 @@ func initConfig() {
157157

158158
appEnvVars := []string{
159159
"google_admin",
160+
"google_sa_email",
160161
"google_credentials",
161162
"scim_access_token",
162163
"scim_endpoint",
@@ -201,6 +202,12 @@ func configLambda() {
201202
}
202203
cfg.GoogleAdmin = unwrap
203204

205+
unwrap, err = secrets.GoogleSAEmail()
206+
if err != nil {
207+
log.Fatalf(errors.Wrap(err, "cannot read config").Error())
208+
}
209+
cfg.GoogleSAEmail = unwrap
210+
204211
unwrap, err = secrets.GoogleCredentials()
205212
if err != nil {
206213
log.Fatalf(errors.Wrap(err, "cannot read config").Error())
@@ -241,6 +248,7 @@ func addFlags(cmd *cobra.Command, cfg *config.Config) {
241248
rootCmd.Flags().StringVarP(&cfg.SCIMEndpoint, "endpoint", "e", "", "AWS SSO SCIM API Endpoint")
242249
rootCmd.Flags().StringVarP(&cfg.GoogleCredentials, "google-credentials", "c", config.DefaultGoogleCredentials, "path to Google Workspace credentials file")
243250
rootCmd.Flags().StringVarP(&cfg.GoogleAdmin, "google-admin", "u", "", "Google Workspace admin user email")
251+
rootCmd.Flags().StringVarP(&cfg.GoogleSAEmail, "google-service-account-email", "W", "", "Google Workload Identity Federation SA email. If set, google-credentials must be associated with a Workload Identity Federation json file")
244252
rootCmd.Flags().StringSliceVar(&cfg.IgnoreUsers, "ignore-users", []string{}, "ignores these Google Workspace users")
245253
rootCmd.Flags().StringSliceVar(&cfg.IgnoreGroups, "ignore-groups", []string{}, "ignores these Google Workspace groups")
246254
rootCmd.Flags().StringSliceVar(&cfg.IncludeGroups, "include-groups", []string{}, "include only these Google Workspace groups, NOTE: only works when --sync-method 'users_groups'")

go.mod

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,36 @@ module github.com/awslabs/ssosync
33
go 1.16
44

55
require (
6-
github.com/BurntSushi/toml v1.0.0
7-
github.com/aws/aws-lambda-go v1.23.0
8-
github.com/aws/aws-sdk-go v1.44.102
9-
github.com/fsnotify/fsnotify v1.4.9 // indirect
10-
github.com/golang/mock v1.5.0
6+
github.com/BurntSushi/toml v1.3.2
7+
github.com/aws/aws-lambda-go v1.41.0
8+
github.com/aws/aws-sdk-go v1.44.319
9+
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c // indirect
10+
github.com/coreos/bbolt v1.3.2 // indirect
11+
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e // indirect
12+
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
13+
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
14+
github.com/golang/mock v1.6.0
15+
github.com/gorilla/websocket v1.4.2 // indirect
16+
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0 // indirect
1117
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
12-
github.com/hashicorp/go-retryablehttp v0.7.0
13-
github.com/magiconair/properties v1.8.5 // indirect
14-
github.com/mitchellh/mapstructure v1.4.1 // indirect
15-
github.com/pelletier/go-toml v1.9.0 // indirect
18+
github.com/hashicorp/go-retryablehttp v0.7.4
19+
github.com/jonboulle/clockwork v0.1.0 // indirect
20+
github.com/pelletier/go-toml v1.9.5 // indirect
21+
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
1622
github.com/pkg/errors v0.9.1
17-
github.com/sirupsen/logrus v1.8.1
18-
github.com/spf13/afero v1.6.0 // indirect
19-
github.com/spf13/cast v1.3.1 // indirect
20-
github.com/spf13/cobra v1.1.3
23+
github.com/prometheus/tsdb v0.7.1 // indirect
24+
github.com/sirupsen/logrus v1.9.3
25+
github.com/smartystreets/goconvey v1.6.4 // indirect
26+
github.com/soheilhy/cmux v0.1.4 // indirect
27+
github.com/spf13/cobra v1.7.0
2128
github.com/spf13/jwalterweatherman v1.1.0 // indirect
22-
github.com/spf13/viper v1.7.1
23-
github.com/stretchr/testify v1.7.0
24-
golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c
25-
google.golang.org/api v0.46.0
26-
gopkg.in/ini.v1 v1.62.0 // indirect
29+
github.com/spf13/viper v1.16.0
30+
github.com/stretchr/testify v1.8.4
31+
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
32+
github.com/urfave/cli/v2 v2.2.0 // indirect
33+
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
34+
go.etcd.io/bbolt v1.3.2 // indirect
35+
golang.org/x/oauth2 v0.11.0
36+
google.golang.org/api v0.136.0
37+
gopkg.in/resty.v1 v1.12.0 // indirect
2738
)

0 commit comments

Comments
 (0)