-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3726 from justinsb/storage_acls
Automatic merge from submit-queue. GCS: Use ACLs for GCE permissions This needs less permissions, but also allows for more granular control over access to files than whole-bucket permissions that IAM gives us.
- Loading branch information
Showing
56 changed files
with
869 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = [ | ||
"interface.go", | ||
"plugins.go", | ||
], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/apis/kops:go_default_library", | ||
"//util/pkg/vfs:go_default_library", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["storage.go"], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/acls:go_default_library", | ||
"//pkg/apis/kops:go_default_library", | ||
"//upup/pkg/fi/cloudup:go_default_library", | ||
"//upup/pkg/fi/cloudup/gce:go_default_library", | ||
"//util/pkg/vfs:go_default_library", | ||
"//vendor/google.golang.org/api/storage/v1:go_default_library", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package gce | ||
|
||
import ( | ||
"fmt" | ||
|
||
storage "google.golang.org/api/storage/v1" | ||
"k8s.io/kops/pkg/acls" | ||
"k8s.io/kops/pkg/apis/kops" | ||
"k8s.io/kops/upup/pkg/fi/cloudup" | ||
"k8s.io/kops/upup/pkg/fi/cloudup/gce" | ||
"k8s.io/kops/util/pkg/vfs" | ||
) | ||
|
||
// gcsAclStrategy is the AclStrategy for objects written to google cloud storage | ||
type gcsAclStrategy struct { | ||
} | ||
|
||
var _ acls.ACLStrategy = &gcsAclStrategy{} | ||
|
||
// GetACL returns the ACL to use if this is a google cloud storage path | ||
func (s *gcsAclStrategy) GetACL(p vfs.Path, cluster *kops.Cluster) (vfs.ACL, error) { | ||
if kops.CloudProviderID(cluster.Spec.CloudProvider) != kops.CloudProviderGCE { | ||
return nil, nil | ||
} | ||
gcsPath, ok := p.(*vfs.GSPath) | ||
if !ok { | ||
return nil, nil | ||
} | ||
|
||
bucketName := gcsPath.Bucket() | ||
client := gcsPath.Client() | ||
|
||
// TODO: Cache? | ||
bucket, err := client.Buckets.Get(bucketName).Do() | ||
if err != nil { | ||
return nil, fmt.Errorf("error querying bucket %q: %v", bucketName, err) | ||
} | ||
|
||
// TODO: Cache? | ||
cloud, err := cloudup.BuildCloud(cluster) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
serviceAccount, err := cloud.(gce.GCECloud).ServiceAccount() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var acls []*storage.ObjectAccessControl | ||
for _, a := range bucket.DefaultObjectAcl { | ||
acls = append(acls, a) | ||
} | ||
|
||
acls = append(acls, &storage.ObjectAccessControl{ | ||
Email: serviceAccount, | ||
Entity: "user-" + serviceAccount, | ||
Role: "READER", | ||
}) | ||
|
||
return &vfs.GSAcl{ | ||
Acl: acls, | ||
}, nil | ||
} | ||
|
||
func Register() { | ||
acls.RegisterPlugin("k8s.io/kops/acl/gce", &gcsAclStrategy{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package acls | ||
|
||
import ( | ||
"k8s.io/kops/pkg/apis/kops" | ||
"k8s.io/kops/util/pkg/vfs" | ||
) | ||
|
||
// ACLStrategy is the interface implemented by ACL strategy providers | ||
type ACLStrategy interface { | ||
// GetACL returns the ACL if this strategy handles the vfs.Path, when writing for the specified cluster | ||
GetACL(p vfs.Path, cluster *kops.Cluster) (vfs.ACL, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
Copyright 2017 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package acls | ||
|
||
import ( | ||
"fmt" | ||
"sync" | ||
|
||
"k8s.io/kops/pkg/apis/kops" | ||
"k8s.io/kops/util/pkg/vfs" | ||
) | ||
|
||
var strategies map[string]ACLStrategy | ||
var strategiesMutex sync.Mutex | ||
|
||
// GetACL returns the ACL for the vfs.Path, by consulting all registered strategies | ||
func GetACL(p vfs.Path, cluster *kops.Cluster) (vfs.ACL, error) { | ||
strategiesMutex.Lock() | ||
defer strategiesMutex.Unlock() | ||
|
||
for k, strategy := range strategies { | ||
acl, err := strategy.GetACL(p, cluster) | ||
if err != nil { | ||
return nil, fmt.Errorf("error from acl provider %q: %v", k, err) | ||
} | ||
if acl != nil { | ||
return acl, nil | ||
} | ||
} | ||
return nil, nil | ||
} | ||
|
||
// RegisterPlugin adds the strategy to the registered strategies | ||
func RegisterPlugin(key string, strategy ACLStrategy) { | ||
strategiesMutex.Lock() | ||
defer strategiesMutex.Unlock() | ||
|
||
if strategies == nil { | ||
strategies = make(map[string]ACLStrategy) | ||
} | ||
|
||
strategies[key] = strategy | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.