-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce the gcp_cloudstorage
BundlePublisher plugin
#4961
Merged
azdagron
merged 3 commits into
spiffe:main
from
amartinezfayo:bundlepublisher-gcp_cloudstorage
Mar 28, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Server plugin: BundlePublisher "gcp_cloudstorage" | ||
|
||
The `gcp_cloudstorage` plugin puts the current trust bundle of the server in a designated | ||
Google Cloud Storage bucket, keeping it updated. | ||
|
||
The plugin accepts the following configuration options: | ||
|
||
| Configuration | Description | Required | Default | | ||
|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------|----------------------------------------------------------------| | ||
| service_account_file | Path to the service account file used to authenticate with the Cloud Storage API. | No. | Value of `GOOGLE_APPLICATION_CREDENTIALS` environment variable.| | ||
| bucket_name | The Google Cloud Storage bucket name to which the trust bundle is uploaded. | Yes. | | | ||
| object_name | The object name inside the bucket. | Yes. | | | ||
| format | Format in which the trust bundle is stored, <spiffe | jwks | pem>. See [Supported bundle formats](#supported-bundle-formats) for more details. | Yes. | | | ||
|
||
## Supported bundle formats | ||
|
||
The following bundle formats are supported: | ||
|
||
### SPIFFE format | ||
|
||
The trust bundle is represented as an RFC 7517 compliant JWK Set, with the specific parameters defined in the [SPIFFE Trust Domain and Bundle specification](https://github.com/spiffe/spiffe/blob/main/standards/SPIFFE_Trust_Domain_and_Bundle.md#4-spiffe-bundle-format). Both the JWT authorities and the X.509 authorities are included. | ||
|
||
### JWKS format | ||
|
||
The trust bundle is encoded as an RFC 7517 compliant JWK Set, omitting SPIFFE-specific parameters. Both the JWT authorities and the X.509 authorities are included. | ||
|
||
### PEM format | ||
|
||
The trust bundle is formatted using PEM encoding. Only the X.509 authorities are included. | ||
|
||
## Required permissions | ||
|
||
The plugin requires the following IAM permissions be granted to the authenticated service account in the configured bucket: | ||
|
||
```text | ||
storage.objects.create | ||
storage.objects.delete | ||
``` | ||
|
||
The `storage.objects.delete` permission is required to overwrite the object when the bundle is updated. | ||
|
||
## Sample configuration using Application Default Credentials | ||
|
||
The following configuration uploads the local trust bundle contents to the `example.org` object in the `spire-bundle` bucket. Since `service_account_file` is not configured, [Application Default Credentials](https://cloud.google.com/docs/authentication/client-libraries#adc) are used. | ||
|
||
```hcl | ||
BundlePublisher "gcp_cloudstorage" { | ||
plugin_data { | ||
bucket = "spire-bundle" | ||
object_name = "example.org" | ||
format = "spiffe" | ||
} | ||
} | ||
``` | ||
|
||
## Sample configuration using service account file | ||
|
||
The following configuration uploads the local trust bundle contents to the `example.org` object in the `spire-bundle` bucket. Since `service_account_file` is configured, authentication to the Cloud Storage API is done with the given service account file. | ||
|
||
```hcl | ||
BundlePublisher "gcp_cloudstorage" { | ||
plugin_data { | ||
service_account_file = "/path/to/service/account/file" | ||
bucket = "spire-bundle" | ||
object_name = "example.org" | ||
format = "spiffe" | ||
} | ||
} | ||
``` |
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
22 changes: 22 additions & 0 deletions
22
pkg/server/plugin/bundlepublisher/gcpcloudstorage/client.go
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,22 @@ | ||
package gcpcloudstorage | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"cloud.google.com/go/storage" | ||
"google.golang.org/api/option" | ||
) | ||
|
||
type gcsService interface { | ||
Bucket(name string) *storage.BucketHandle | ||
Close() error | ||
} | ||
|
||
func newGCSClient(ctx context.Context, opts ...option.ClientOption) (gcsService, error) { | ||
return storage.NewClient(ctx, opts...) | ||
} | ||
|
||
func newStorageWriter(ctx context.Context, o *storage.ObjectHandle) io.WriteCloser { | ||
return o.NewWriter(ctx) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it possible to update? instead of deleting? or that is the way gcp api works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is how the Google Cloud Storage API works, as documented here: https://cloud.google.com/storage/docs/uploading-objects#roles-and-permissions