Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit abed833

Browse files
authored
Merge pull request #190 from secrethub/release/v0.29.0
Release v0.29.0
2 parents 70beffe + b4d66e0 commit abed833

26 files changed

+1148
-188
lines changed

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module github.com/secrethub/secrethub-go
22

33
require (
44
bitbucket.org/zombiezen/cardcpx v0.0.0-20150417151802-902f68ff43ef
5+
cloud.google.com/go v0.56.0
56
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf
67
github.com/aws/aws-sdk-go v1.25.49
78
github.com/docker/docker v1.13.1
@@ -13,9 +14,9 @@ require (
1314
github.com/mattn/go-shellwords v1.0.6 // indirect
1415
github.com/mitchellh/go-homedir v1.1.0
1516
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
16-
github.com/stretchr/testify v1.3.0 // indirect
17-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
18-
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 // indirect
17+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
18+
google.golang.org/api v0.26.0
19+
google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940
1920
)
2021

2122
go 1.13

go.sum

Lines changed: 279 additions & 4 deletions
Large diffs are not rendered by default.

internals/api/auth.go

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import (
1010

1111
// AuthMethod options
1212
const (
13-
AuthMethodAWSSTS = "aws-sts"
13+
AuthMethodAWSSTS = "aws-sts"
14+
AuthMethodGCPServiceAccount = "gcp-service-account"
1415
)
1516

1617
// SessionType options
@@ -20,18 +21,13 @@ const (
2021

2122
// Errors
2223
var (
23-
ErrInvalidSessionType = errAPI.Code("invalid_session_type").StatusError("invalid session type provided for authentication request", http.StatusBadRequest)
24-
ErrInvalidPayload = errAPI.Code("invalid_payload").StatusError("invalid payload provided for authentication request", http.StatusBadRequest)
25-
ErrInvalidAuthMethod = errAPI.Code("invalid_auth_method").StatusError("invalid auth method", http.StatusBadRequest)
26-
ErrMissingField = errAPI.Code("missing_field").StatusErrorPref("request is missing field %s", http.StatusBadRequest)
27-
ErrSessionNotFound = errAPI.Code("session_not_found").StatusError("session could not be found, it might have expired", http.StatusForbidden)
28-
ErrSessionExpired = errAPI.Code("session_expired").StatusError("session has expired", http.StatusForbidden)
29-
ErrAuthFailed = errAPI.Code("auth_failed").StatusError("authentication failed", http.StatusForbidden)
30-
ErrCouldNotGetEndpoint = errAPI.Code("aws_endpoint_not_found").StatusError("could not find an AWS endpoint for the provided region", http.StatusBadRequest)
31-
ErrAWSException = errAPI.Code("aws_exception").StatusError("encountered an unexpected problem while verifying your identity on AWS. Please try again later.", http.StatusFailedDependency)
32-
ErrNoServiceWithRole = errAPI.Code("no_service_with_role").StatusErrorPref("no service account found that is linked to the IAM role '%s'", http.StatusNotFound)
33-
ErrNoAWSCredentials = errAPI.Code("missing_aws_credentials").StatusError("request was not signed with AWS credentials", http.StatusUnauthorized)
34-
ErrInvalidAWSCredentials = errAPI.Code("invalid_aws_credentials").StatusError("credentials were not accepted by AWS", http.StatusUnauthorized)
24+
ErrInvalidSessionType = errAPI.Code("invalid_session_type").StatusError("invalid session type provided for authentication request", http.StatusBadRequest)
25+
ErrInvalidPayload = errAPI.Code("invalid_payload").StatusError("invalid payload provided for authentication request", http.StatusBadRequest)
26+
ErrInvalidAuthMethod = errAPI.Code("invalid_auth_method").StatusError("invalid auth method", http.StatusBadRequest)
27+
ErrMissingField = errAPI.Code("missing_field").StatusErrorPref("request is missing field %s", http.StatusBadRequest)
28+
ErrSessionNotFound = errAPI.Code("session_not_found").StatusError("session could not be found, it might have expired", http.StatusForbidden)
29+
ErrSessionExpired = errAPI.Code("session_expired").StatusError("session has expired", http.StatusForbidden)
30+
ErrAuthFailed = errAPI.Code("auth_failed").StatusError("authentication failed", http.StatusForbidden)
3531
)
3632

3733
// SessionType defines how a session can be used.
@@ -44,24 +40,6 @@ type AuthRequest struct {
4440
Payload interface{} `json:"payload"`
4541
}
4642

47-
// AuthPayloadAWSSTS is the authentication payload used for authenticating with AWS STS.
48-
type AuthPayloadAWSSTS struct {
49-
Region string `json:"region"`
50-
Request []byte `json:"request"`
51-
}
52-
53-
// NewAuthRequestAWSSTS returns a new AuthRequest for authentication using AWS STS.
54-
func NewAuthRequestAWSSTS(sessionType SessionType, region string, stsRequest []byte) AuthRequest {
55-
return AuthRequest{
56-
Method: AuthMethodAWSSTS,
57-
SessionType: sessionType,
58-
Payload: &AuthPayloadAWSSTS{
59-
Region: region,
60-
Request: stsRequest,
61-
},
62-
}
63-
}
64-
6543
// UnmarshalJSON converts a JSON representation into a AuthRequest with the correct Payload.
6644
func (r *AuthRequest) UnmarshalJSON(b []byte) error {
6745
// Declare a private type to avoid recursion into this function.
@@ -84,6 +62,8 @@ func (r *AuthRequest) UnmarshalJSON(b []byte) error {
8462
switch dec.Method {
8563
case AuthMethodAWSSTS:
8664
dec.Payload = &AuthPayloadAWSSTS{}
65+
case AuthMethodGCPServiceAccount:
66+
dec.Payload = &AuthPayloadGCPServiceAccount{}
8767
default:
8868
return ErrInvalidAuthMethod
8969
}
@@ -118,23 +98,20 @@ func (r *AuthRequest) Validate() error {
11898
if err := authPayload.Validate(); err != nil {
11999
return err
120100
}
101+
case AuthMethodGCPServiceAccount:
102+
authPayload, ok := r.Payload.(*AuthPayloadGCPServiceAccount)
103+
if !ok {
104+
return ErrInvalidPayload
105+
}
106+
if err := authPayload.Validate(); err != nil {
107+
return err
108+
}
121109
default:
122110
return ErrInvalidAuthMethod
123111
}
124112
return nil
125113
}
126114

127-
// Validate whether the AuthPayloadAWSSTS is valid.
128-
func (pl AuthPayloadAWSSTS) Validate() error {
129-
if pl.Region == "" {
130-
return ErrMissingField("region")
131-
}
132-
if pl.Request == nil {
133-
return ErrMissingField("request")
134-
}
135-
return nil
136-
}
137-
138115
// NewSessionHMAC returns a HMAC type api.Session.
139116
func NewSessionHMAC(sessionID uuid.UUID, expiration time.Time, secretKey string) *Session {
140117
return &Session{

internals/api/auth_aws.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package api
2+
3+
import "net/http"
4+
5+
// Errors
6+
var (
7+
ErrCouldNotGetEndpoint = errAPI.Code("aws_endpoint_not_found").StatusError("could not find an AWS endpoint for the provided region", http.StatusBadRequest)
8+
ErrAWSException = errAPI.Code("aws_exception").StatusError("encountered an unexpected problem while verifying your identity on AWS. Please try again later.", http.StatusFailedDependency)
9+
ErrNoServiceWithRole = errAPI.Code("no_service_with_role").StatusErrorPref("no service account found that is linked to the IAM role '%s'", http.StatusNotFound)
10+
ErrNoAWSCredentials = errAPI.Code("missing_aws_credentials").StatusError("request was not signed with AWS credentials", http.StatusUnauthorized)
11+
ErrInvalidAWSCredentials = errAPI.Code("invalid_aws_credentials").StatusError("credentials were not accepted by AWS", http.StatusUnauthorized)
12+
)
13+
14+
// AuthPayloadAWSSTS is the authentication payload used for authenticating with AWS STS.
15+
type AuthPayloadAWSSTS struct {
16+
Region string `json:"region"`
17+
Request []byte `json:"request"`
18+
}
19+
20+
// NewAuthRequestAWSSTS returns a new AuthRequest for authentication using AWS STS.
21+
func NewAuthRequestAWSSTS(sessionType SessionType, region string, stsRequest []byte) AuthRequest {
22+
return AuthRequest{
23+
Method: AuthMethodAWSSTS,
24+
SessionType: sessionType,
25+
Payload: &AuthPayloadAWSSTS{
26+
Region: region,
27+
Request: stsRequest,
28+
},
29+
}
30+
}
31+
32+
// Validate whether the AuthPayloadAWSSTS is valid.
33+
func (pl AuthPayloadAWSSTS) Validate() error {
34+
if pl.Region == "" {
35+
return ErrMissingField("region")
36+
}
37+
if pl.Request == nil {
38+
return ErrMissingField("request")
39+
}
40+
return nil
41+
}

internals/api/auth_gcp.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package api
2+
3+
import "net/http"
4+
5+
// Errors
6+
var (
7+
ErrInvalidGCPIDToken = errAPI.Code("invalid_id_token").StatusError("provided id_token is invalid", http.StatusBadRequest)
8+
ErrNoGCPServiceWithEmail = errAPI.Code("no_service_with_email").StatusErrorPref("no service account found that is linked to the GCP Service Account %s'", http.StatusUnauthorized)
9+
)
10+
11+
// AuthPayloadGCPServiceAccount is the authentication payload used for authenticating with a GCP Service Account.
12+
type AuthPayloadGCPServiceAccount struct {
13+
IDToken string `json:"id_token"`
14+
}
15+
16+
// NewAuthRequestGCPServiceAccount returns a new AuthRequest for authentication using a GCP Service Account.
17+
func NewAuthRequestGCPServiceAccount(sessionType SessionType, idToken string) AuthRequest {
18+
return AuthRequest{
19+
Method: AuthMethodGCPServiceAccount,
20+
SessionType: sessionType,
21+
Payload: &AuthPayloadGCPServiceAccount{
22+
IDToken: idToken,
23+
},
24+
}
25+
}
26+
27+
func (pl AuthPayloadGCPServiceAccount) Validate() error {
28+
if pl.IDToken == "" {
29+
return ErrMissingField("id_token")
30+
}
31+
return nil
32+
}

0 commit comments

Comments
 (0)