Skip to content

Commit 07d26d9

Browse files
authored
Adds TokenRevokeType field to credential providers. (#2075)
1 parent 00cd5a9 commit 07d26d9

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

pkg/credentials/assume_role.go

+5
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ type STSAssumeRoleOptions struct {
104104
RoleARN string
105105
RoleSessionName string
106106
ExternalID string
107+
108+
TokenRevokeType string // Optional, used for token revokation (MinIO only extension)
107109
}
108110

109111
// NewSTSAssumeRole returns a pointer to a new
@@ -161,6 +163,9 @@ func getAssumeRoleCredentials(clnt *http.Client, endpoint string, opts STSAssume
161163
if opts.ExternalID != "" {
162164
v.Set("ExternalId", opts.ExternalID)
163165
}
166+
if opts.TokenRevokeType != "" {
167+
v.Set("TokenRevokeType", opts.TokenRevokeType)
168+
}
164169

165170
u, err := url.Parse(endpoint)
166171
if err != nil {

pkg/credentials/sts_custom_identity.go

+6
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ type CustomTokenIdentity struct {
6969
// RequestedExpiry is to set the validity of the generated credentials
7070
// (this value bounded by server).
7171
RequestedExpiry time.Duration
72+
73+
// Optional, used for token revokation
74+
TokenRevokeType string
7275
}
7376

7477
// RetrieveWithCredContext with Retrieve optionally cred context
@@ -98,6 +101,9 @@ func (c *CustomTokenIdentity) RetrieveWithCredContext(cc *CredContext) (value Va
98101
if c.RequestedExpiry != 0 {
99102
v.Set("DurationSeconds", fmt.Sprintf("%d", int(c.RequestedExpiry.Seconds())))
100103
}
104+
if c.TokenRevokeType != "" {
105+
v.Set("TokenRevokeType", c.TokenRevokeType)
106+
}
101107

102108
u.RawQuery = v.Encode()
103109

pkg/credentials/sts_ldap_identity.go

+6
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ type LDAPIdentity struct {
7373
// RequestedExpiry is the configured expiry duration for credentials
7474
// requested from LDAP.
7575
RequestedExpiry time.Duration
76+
77+
// Optional, used for token revokation
78+
TokenRevokeType string
7679
}
7780

7881
// NewLDAPIdentity returns new credentials object that uses LDAP
@@ -152,6 +155,9 @@ func (k *LDAPIdentity) RetrieveWithCredContext(cc *CredContext) (value Value, er
152155
if k.RequestedExpiry != 0 {
153156
v.Set("DurationSeconds", fmt.Sprintf("%d", int(k.RequestedExpiry.Seconds())))
154157
}
158+
if k.TokenRevokeType != "" {
159+
v.Set("TokenRevokeType", k.TokenRevokeType)
160+
}
155161

156162
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(v.Encode()))
157163
if err != nil {

pkg/credentials/sts_tls_identity.go

+6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ type STSCertificateIdentity struct {
8080
// Certificate is the client certificate that is used for
8181
// STS authentication.
8282
Certificate tls.Certificate
83+
84+
// Optional, used for token revokation
85+
TokenRevokeType string
8386
}
8487

8588
// NewSTSCertificateIdentity returns a STSCertificateIdentity that authenticates
@@ -122,6 +125,9 @@ func (i *STSCertificateIdentity) RetrieveWithCredContext(cc *CredContext) (Value
122125
queryValues := url.Values{}
123126
queryValues.Set("Action", "AssumeRoleWithCertificate")
124127
queryValues.Set("Version", STSVersion)
128+
if i.TokenRevokeType != "" {
129+
queryValues.Set("TokenRevokeType", i.TokenRevokeType)
130+
}
125131
endpointURL.RawQuery = queryValues.Encode()
126132

127133
req, err := http.NewRequest(http.MethodPost, endpointURL.String(), nil)

pkg/credentials/sts_web_identity.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ type STSWebIdentity struct {
9393

9494
// roleSessionName is the identifier for the assumed role session.
9595
roleSessionName string
96+
97+
// Optional, used for token revokation
98+
TokenRevokeType string
9699
}
97100

98101
// NewSTSWebIdentity returns a pointer to a new
@@ -135,7 +138,7 @@ func WithPolicy(policy string) func(*STSWebIdentity) {
135138
}
136139

137140
func getWebIdentityCredentials(clnt *http.Client, endpoint, roleARN, roleSessionName string, policy string,
138-
getWebIDTokenExpiry func() (*WebIdentityToken, error),
141+
getWebIDTokenExpiry func() (*WebIdentityToken, error), tokenRevokeType string,
139142
) (AssumeRoleWithWebIdentityResponse, error) {
140143
idToken, err := getWebIDTokenExpiry()
141144
if err != nil {
@@ -168,6 +171,9 @@ func getWebIdentityCredentials(clnt *http.Client, endpoint, roleARN, roleSession
168171
v.Set("Policy", policy)
169172
}
170173
v.Set("Version", STSVersion)
174+
if tokenRevokeType != "" {
175+
v.Set("TokenRevokeType", tokenRevokeType)
176+
}
171177

172178
u, err := url.Parse(endpoint)
173179
if err != nil {
@@ -236,7 +242,7 @@ func (m *STSWebIdentity) RetrieveWithCredContext(cc *CredContext) (Value, error)
236242
return Value{}, errors.New("STS endpoint unknown")
237243
}
238244

239-
a, err := getWebIdentityCredentials(client, stsEndpoint, m.RoleARN, m.roleSessionName, m.Policy, m.GetWebIDTokenExpiry)
245+
a, err := getWebIdentityCredentials(client, stsEndpoint, m.RoleARN, m.roleSessionName, m.Policy, m.GetWebIDTokenExpiry, m.TokenRevokeType)
240246
if err != nil {
241247
return Value{}, err
242248
}

0 commit comments

Comments
 (0)