Skip to content
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

feat: Add scaffolding as well as implementation for rotation_handler #1

Merged
merged 9 commits into from
Apr 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions cmd/cert-rotation/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2022 Google LLC
//
// 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 main

import (
"context"
"log"
"os/signal"
"syscall"

kms "cloud.google.com/go/kms/apiv1"
)

// TODO: Switch to graceful termination. https://github.com/abcxyz/jvs/issues/3
func main() {
// To capture TERM signal.
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
defer stop()

kmsClient, err := kms.NewKeyManagementClient(ctx)
if err != nil {
log.Fatalf("failed to setup client: %v", err)
}
defer kmsClient.Close()

// TODO: Set up server with mux. https://github.com/abcxyz/jvs/issues/8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tip: a simpler way is to "TODO(#8)"

}
30 changes: 30 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module github.com/abcxyz/jvs

go 1.18

require (
cloud.google.com/go/kms v1.4.0
github.com/golang/protobuf v1.5.2
github.com/google/go-cmp v0.5.7
github.com/hashicorp/go-multierror v1.1.1
google.golang.org/api v0.70.0
google.golang.org/genproto v0.0.0-20220222213610-43724f9ea8cf
google.golang.org/grpc v1.44.0
google.golang.org/protobuf v1.27.1
)

require (
cloud.google.com/go v0.100.2 // indirect
cloud.google.com/go/compute v1.3.0 // indirect
cloud.google.com/go/iam v0.1.0 // indirect
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e // indirect
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/appengine v1.6.7 // indirect
)
596 changes: 596 additions & 0 deletions go.sum

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions pkg/config/crypto_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2022 Google LLC
//
// 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 v1alpha1 provides apis that users will interact with.
package config

import "time"

const (
// Version of the API and config.
Version = "v1alpha1"
)

// CryptoConfig is the full jvs config.
type CryptoConfig struct {
// Version is the version of the config.
Version string `yaml:"version,omitempty" env:"VERSION,overwrite"`

// Crypto variables
KeyTTL time.Duration `yaml:"key_ttl,omitempty"`
PropagationTime time.Duration `yaml:"propagation_time,omitempty"`
GracePeriod time.Duration `yaml:"grace_period,omitempty"`
DisabledPeriod time.Duration `yaml:"disabled_period,omitempty"`
}

// Validate checks if the config is valid.
func (cfg *CryptoConfig) Validate() error {
// TODO https://github.com/abcxyz/jvs/issues/2
cfg.SetDefault()
return nil
}

// SetDefault sets default for the config.
func (cfg *CryptoConfig) SetDefault() {
// TODO: set defaults for other fields if necessary.
if cfg.Version == "" {
cfg.Version = Version
}
}

// GetRotationAge gets the duration after a key has been created that a new key should be created.
func (cfg *CryptoConfig) GetRotationAge() time.Duration {
return cfg.KeyTTL - cfg.GracePeriod
}

// GetDestroyAge gets the duration after a key has been created when it becomes a candidate to be destroyed.
func (cfg *CryptoConfig) GetDestroyAge() time.Duration {
return cfg.KeyTTL + cfg.DisabledPeriod
}
17 changes: 17 additions & 0 deletions pkg/config/crypto_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2022 Google LLC
//
// 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 config

// TODO https://github.com/abcxyz/jvs/issues/2
Loading