Skip to content

Commit cdb0bf4

Browse files
author
Rui Hu
committed
cloud: add version gate for auth via assume role in AWS and GCP storage and KMS
Add a version gate for auth via assume role in AWS and GCP storage and KMS to prevent this type of auth until all nodes in the cluster has been upgraded to 22.2. The gate prevents a class of job failures where sometimes a job can succeed with assume role auth if its processors happen to all be on 22.2 nodes, but fail at times when one of its processor nodes don't support assume role. This version gate preempts the issue by preventing this type of auth until the cluster has been finalized on 22.2 and gives a better error message of why the auth cannot be used. It's important to note that this gate does not prevent a user from creating a BACKUP job that uses assume role auth, e.g. via the DETACHED option, because the destination storage is not accessed during planning. This is inline with existing behavior for other types of auth errors, e.g. if the user enters incorrect credentials. The BACKUP job will still fail with the version gate error when it eventually executes. Release note: None
1 parent 089d9c0 commit cdb0bf4

10 files changed

Lines changed: 34 additions & 4 deletions

File tree

docs/generated/settings/settings-for-tenants.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,4 +296,4 @@ trace.jaeger.agent string the address of a Jaeger agent to receive traces using
296296
trace.opentelemetry.collector string address of an OpenTelemetry trace collector to receive traces using the otel gRPC protocol, as <host>:<port>. If no port is specified, 4317 will be used.
297297
trace.span_registry.enabled boolean true if set, ongoing traces can be seen at https://<ui>/#/debug/tracez
298298
trace.zipkin.collector string the address of a Zipkin instance to receive traces, as <host>:<port>. If no port is specified, 9411 will be used.
299-
version version 1000022.1-72 set the active cluster version in the format '<major>.<minor>'
299+
version version 1000022.1-74 set the active cluster version in the format '<major>.<minor>'

docs/generated/settings/settings.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,6 @@
230230
<tr><td><code>trace.opentelemetry.collector</code></td><td>string</td><td><code></code></td><td>address of an OpenTelemetry trace collector to receive traces using the otel gRPC protocol, as <host>:<port>. If no port is specified, 4317 will be used.</td></tr>
231231
<tr><td><code>trace.span_registry.enabled</code></td><td>boolean</td><td><code>true</code></td><td>if set, ongoing traces can be seen at https://<ui>/#/debug/tracez</td></tr>
232232
<tr><td><code>trace.zipkin.collector</code></td><td>string</td><td><code></code></td><td>the address of a Zipkin instance to receive traces, as <host>:<port>. If no port is specified, 9411 will be used.</td></tr>
233-
<tr><td><code>version</code></td><td>version</td><td><code>1000022.1-72</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
233+
<tr><td><code>version</code></td><td>version</td><td><code>1000022.1-74</code></td><td>set the active cluster version in the format '<major>.<minor>'</td></tr>
234234
</tbody>
235235
</table>

pkg/cloud/amazon/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ go_library(
1818
"//pkg/cloud/externalconn",
1919
"//pkg/cloud/externalconn/connectionpb",
2020
"//pkg/cloud/externalconn/utils",
21+
"//pkg/clusterversion",
2122
"//pkg/security/username",
2223
"//pkg/server/telemetry",
2324
"//pkg/settings",

pkg/cloud/amazon/aws_kms.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/aws/aws-sdk-go/aws/session"
2222
"github.com/aws/aws-sdk-go/service/kms"
2323
"github.com/cockroachdb/cockroach/pkg/cloud"
24+
"github.com/cockroachdb/cockroach/pkg/clusterversion"
2425
"github.com/cockroachdb/errors"
2526
)
2627

@@ -161,6 +162,10 @@ func MakeAWSKMS(ctx context.Context, uri string, env cloud.KMSEnv) (cloud.KMS, e
161162
}
162163

163164
if kmsURIParams.roleARN != "" {
165+
if !env.ClusterSettings().Version.IsActive(ctx, clusterversion.SupportAssumeRoleAuth) {
166+
return nil, errors.New("cannot authenticate to KMS via assume role until cluster has fully upgraded to 22.2")
167+
}
168+
164169
// If there are delegate roles in the assume-role chain, we create a session
165170
// for each role in order for it to fetch the credentials from the next role
166171
// in the chain.

pkg/cloud/amazon/s3_storage.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"github.com/cockroachdb/cockroach/pkg/base"
3434
"github.com/cockroachdb/cockroach/pkg/cloud"
3535
"github.com/cockroachdb/cockroach/pkg/cloud/cloudpb"
36+
"github.com/cockroachdb/cockroach/pkg/clusterversion"
3637
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
3738
"github.com/cockroachdb/cockroach/pkg/settings"
3839
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
@@ -470,6 +471,10 @@ func newClient(
470471
}
471472

472473
if conf.roleARN != "" {
474+
if !settings.Version.IsActive(ctx, clusterversion.SupportAssumeRoleAuth) {
475+
return s3Client{}, "", errors.New("cannot authenticate to cloud storage via assume role until cluster has fully upgraded to 22.2")
476+
}
477+
473478
for _, role := range conf.delegateRoleARNs {
474479
intermediateCreds := stscreds.NewCredentials(sess, role)
475480
opts.Config.Credentials = intermediateCreds

pkg/cloud/gcp/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ go_library(
1919
"//pkg/cloud/externalconn",
2020
"//pkg/cloud/externalconn/connectionpb",
2121
"//pkg/cloud/externalconn/utils",
22+
"//pkg/clusterversion",
2223
"//pkg/security/username",
2324
"//pkg/server/telemetry",
2425
"//pkg/settings",

pkg/cloud/gcp/gcp_kms.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
kms "cloud.google.com/go/kms/apiv1"
2020
"github.com/cockroachdb/cockroach/pkg/cloud"
21+
"github.com/cockroachdb/cockroach/pkg/clusterversion"
2122
"github.com/cockroachdb/errors"
2223
"google.golang.org/api/option"
2324
kmspb "google.golang.org/genproto/googleapis/cloud/kms/v1"
@@ -126,6 +127,10 @@ func MakeGCSKMS(ctx context.Context, uri string, env cloud.KMSEnv) (cloud.KMS, e
126127
if kmsURIParams.assumeRole == "" {
127128
opts = append(opts, credentialsOpt...)
128129
} else {
130+
if !env.ClusterSettings().Version.IsActive(ctx, clusterversion.SupportAssumeRoleAuth) {
131+
return nil, errors.New("cannot authenticate to KMS via assume role until cluster has fully upgraded to 22.2")
132+
}
133+
129134
assumeOpt, err := createImpersonateCredentials(ctx, kmsURIParams.assumeRole, kmsURIParams.delegateRoles, kms.DefaultAuthScopes(), credentialsOpt...)
130135
if err != nil {
131136
return nil, errors.Wrapf(err, "failed to assume role")

pkg/cloud/gcp/gcs_storage.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/cockroachdb/cockroach/pkg/base"
2525
"github.com/cockroachdb/cockroach/pkg/cloud"
2626
"github.com/cockroachdb/cockroach/pkg/cloud/cloudpb"
27+
"github.com/cockroachdb/cockroach/pkg/clusterversion"
2728
"github.com/cockroachdb/cockroach/pkg/server/telemetry"
2829
"github.com/cockroachdb/cockroach/pkg/settings"
2930
"github.com/cockroachdb/cockroach/pkg/settings/cluster"
@@ -181,6 +182,10 @@ func makeGCSStorage(
181182
if conf.AssumeRole == "" {
182183
opts = append(opts, credentialsOpt...)
183184
} else {
185+
if !args.Settings.Version.IsActive(ctx, clusterversion.SupportAssumeRoleAuth) {
186+
return nil, errors.New("cannot authenticate to cloud storage via assume role until cluster has fully upgraded to 22.2")
187+
}
188+
184189
assumeOpt, err := createImpersonateCredentials(ctx, conf.AssumeRole, conf.AssumeRoleDelegates, []string{scope}, credentialsOpt...)
185190
if err != nil {
186191
return nil, errors.Wrapf(err, "failed to assume role")

pkg/clusterversion/cockroach_versions.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ const (
298298
// leases to nodes that (i) don't expect them for certain keyspans, and (ii)
299299
// don't know to upgrade them to efficient epoch-based ones.
300300
EnableLeaseUpgrade
301+
// SupportAssumeRoleAuth is the version where assume role authorization is
302+
// supported in cloud storage and KMS.
303+
SupportAssumeRoleAuth
301304

302305
// *************************************************
303306
// Step (1): Add new versions here.
@@ -481,6 +484,10 @@ var rawVersionsSingleton = keyedVersions{
481484
Key: EnableLeaseUpgrade,
482485
Version: roachpb.Version{Major: 22, Minor: 1, Internal: 72},
483486
},
487+
{
488+
Key: SupportAssumeRoleAuth,
489+
Version: roachpb.Version{Major: 22, Minor: 1, Internal: 74},
490+
},
484491

485492
// *************************************************
486493
// Step (2): Add new versions here.

pkg/clusterversion/key_string.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)