Skip to content

Commit a421032

Browse files
author
adisky
committed
Deployment barbican-kms-plugin
Implement Makefile, Dockefile, pod manifests
1 parent 5a8e955 commit a421032

File tree

9 files changed

+79
-16
lines changed

9 files changed

+79
-16
lines changed

Gopkg.lock

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

+17-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ endif
5959
depend-update: work
6060
dep ensure -update -v
6161

62-
build: openstack-cloud-controller-manager cinder-provisioner cinder-flex-volume-driver cinder-csi-plugin k8s-keystone-auth client-keystone-auth octavia-ingress-controller manila-provisioner
62+
build: openstack-cloud-controller-manager cinder-provisioner cinder-flex-volume-driver cinder-csi-plugin k8s-keystone-auth client-keystone-auth octavia-ingress-controller manila-provisioner barbican-kms-plugin
6363

6464
openstack-cloud-controller-manager: depend $(SOURCES)
6565
CGO_ENABLED=0 GOOS=$(GOOS) go build \
@@ -109,6 +109,12 @@ manila-provisioner: depend $(SOURCES)
109109
-o manila-provisioner \
110110
cmd/manila-provisioner/main.go
111111

112+
barbican-kms-plugin: depend $(SOURCES)
113+
cd $(DEST) && CGO_ENABLED=0 GOOS=$(GOOS) go build \
114+
-ldflags $(LDFLAGS) \
115+
-o barbican-kms-plugin \
116+
cmd/barbican-kms-plugin/main.go
117+
112118
test: unit functional
113119

114120
check: depend fmt vet lint import-boss
@@ -193,7 +199,7 @@ realclean: clean
193199
shell:
194200
$(SHELL) -i
195201

196-
images: image-controller-manager image-flex-volume-driver image-provisioner image-csi-plugin image-k8s-keystone-auth image-octavia-ingress-controller image-manila-provisioner
202+
images: image-controller-manager image-flex-volume-driver image-provisioner image-csi-plugin image-k8s-keystone-auth image-octavia-ingress-controller image-manila-provisioner image-kms-plugin
197203

198204
image-controller-manager: depend openstack-cloud-controller-manager
199205
ifeq ($(GOOS),linux)
@@ -258,6 +264,15 @@ else
258264
$(error Please set GOOS=linux for building the image)
259265
endif
260266

267+
image-kms-plugin: depend barbican-kms-plugin
268+
ifeq ($(GOOS), linux)
269+
cp barbican-kms-plugin cluster/images/barbican-kms-plugin
270+
docker build -t $(REGISTRY)/barbican-kms-plugin:$(VERSION) cluster/images/barbican-kms-plugin
271+
rm cluster/images/barbican-kms-plugin/barbican-kms-plugin
272+
else
273+
$(error Please set GOOS=linux for building the image)
274+
endif
275+
261276
upload-images: images
262277
@echo "push images to $(REGISTRY)"
263278
docker login -u="$(DOCKER_USERNAME)" -p="$(DOCKER_PASSWORD)";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM alpine:3.7
2+
LABEL maintainers="Kubernetes Authors"
3+
LABEL description="Barbican KMS Plugin"
4+
5+
ADD barbican-kms-plugin /bin/
6+
7+
CMD ["sh", "-c", "/bin/barbican-kms-plugin --socketpath ${socketpath} --cloud-config ${cloudconfig}"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
kind: EncryptionConfig
2+
apiVersion: v1
3+
resources:
4+
- resources:
5+
- secrets
6+
providers:
7+
- kms:
8+
name : barbican
9+
endpoint: unix:///var/lib/kms/kms.sock
10+
cachesize: 20
11+
- identity: {}

manifests/barbican-kms/pod.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: barbican-kms
5+
spec:
6+
containers:
7+
- name: barbican-kms
8+
image: docker.io/k8scloudprovider/barbican-kms-plugin:latest
9+
args:
10+
- "--socketpath=/kms/kms.sock"
11+
- "--cloud-config=/etc/kubernetes/cloud-config"
12+
volumeMounts:
13+
- name: cloud-config
14+
mountPath: /etc/kubernetes/
15+
- name: socket-dir
16+
mountPath: /kms/
17+
volumes:
18+
- name: config
19+
hostPath:
20+
path: /etc/kubernetes
21+
- name: socket-dir
22+
hostPath:
23+
path: /var/lib/kms/
24+
type: DirectoryOrCreate

pkg/kms/barbican/barbican.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
)
99

1010
type BarbicanService interface {
11-
GetSecret(cfg *Config) ([]byte, error)
11+
GetSecret(cfg Config) ([]byte, error)
1212
}
1313

1414
type KMSOpts struct {
@@ -52,7 +52,7 @@ func (cfg Config) toAuthOptions() gophercloud.AuthOptions {
5252
}
5353

5454
// NewBarbicanClient creates new BarbicanClient
55-
func newBarbicanClient(cfg *Config) (client *gophercloud.ServiceClient, err error) {
55+
func newBarbicanClient(cfg Config) (client *gophercloud.ServiceClient, err error) {
5656

5757
provider, err := openstack.AuthenticatedClient(cfg.toAuthOptions())
5858

@@ -71,7 +71,7 @@ func newBarbicanClient(cfg *Config) (client *gophercloud.ServiceClient, err erro
7171
}
7272

7373
// GetSecret gets unencrypted secret
74-
func (barbican *Barbican) GetSecret(cfg *Config) ([]byte, error) {
74+
func (barbican *Barbican) GetSecret(cfg Config) ([]byte, error) {
7575

7676
client, err := newBarbicanClient(cfg)
7777

pkg/kms/barbican/fake_barbican.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "encoding/hex"
55
type FakeBarbican struct {
66
}
77

8-
func (client *FakeBarbican) GetSecret(cfg *Config) ([]byte, error) {
8+
func (client *FakeBarbican) GetSecret(cfg Config) ([]byte, error) {
99
return hex.DecodeString("6368616e676520746869732070617373")
1010

1111
}

pkg/kms/client/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func main() {
1414

15-
connection, err := grpc.Dial("unix:///tmp/socketfile.sock", grpc.WithInsecure())
15+
connection, err := grpc.Dial("unix:///var/lib/kms/kms.sock", grpc.WithInsecure())
1616
defer connection.Close()
1717
if err != nil {
1818
fmt.Printf("\nConnection to KMS plugin failed, error: %v", err)

pkg/kms/server/server.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ const (
2424

2525
// KMSserver struct
2626
type KMSserver struct {
27-
cfg *barbican.Config
27+
cfg barbican.Config
2828
barbican barbican.BarbicanService
2929
}
3030

31-
func initConfig(configFilePath string) (cfg *barbican.Config, err error) {
31+
func initConfig(configFilePath string, cfg *barbican.Config) error {
3232

3333
config, err := os.Open(configFilePath)
3434
defer config.Close()
3535
if err != nil {
36-
return nil, err
36+
return err
3737
}
3838
err = gcfg.FatalOnly(gcfg.ReadInto(cfg, config))
3939
if err != nil {
40-
return nil, err
40+
return err
4141
}
42-
return cfg, nil
42+
return nil
4343
}
4444

4545
// Run Grpc server for barbican KMS
4646
func Run(configFilePath string, socketpath string, sigchan <-chan os.Signal) (err error) {
4747

4848
glog.Infof("Barbican KMS Plugin Starting Version: %s, RunTimeVersion: %s", version, runtimeversion)
4949
s := new(KMSserver)
50-
s.cfg, err = initConfig(configFilePath)
50+
err = initConfig(configFilePath, &s.cfg)
5151
s.barbican = &barbican.Barbican{}
5252
if err != nil {
5353
glog.V(4).Infof("Error in Getting Config File: %v", err)

0 commit comments

Comments
 (0)