Skip to content

Commit

Permalink
Moved trigger and blacklister to ssadmin
Browse files Browse the repository at this point in the history
This commit moves the in-container admin functions to a new admin
executable. In particular, trigger and blacklisting functionality
has been moved into a single ssadmin command in the controller
image. All necessary changes to dockerfile, Makefile and gitignore
are included.
  • Loading branch information
anzboi committed Feb 19, 2019
1 parent 2bf46c5 commit f173ef9
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 67 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
.glide/

/controller
/ssadmin
/kubeseal
/controller.image
/*-static
/controller.yaml
/sealedsecret-crd.yaml
/docker/controller
/docker/ssadmin
*.iml
.idea
16 changes: 5 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,16 @@ endif

GO_LD_FLAGS = -X main.VERSION=$(VERSION)

all: controller trigger kubeseal
all: controller ssadmin kubeseal

generate: $(GO_FILES)
$(GO) generate $(GO_PACKAGES)

controller: $(GO_FILES)
$(GO) build -o $@ $(GO_FLAGS) -ldflags "$(GO_LD_FLAGS)" ./cmd/controller

trigger: $(GO_FILES)
$(GO) build -o $@ $(GO_FLAGS) -ldflags "$(GO_LD_FLAGS)" ./cmd/trigger

blacklist: $(GO_FILES)
$(GO) build -o $@ $(GO_FLAGS) -ldflags "$(GO_LD_FLAGS)" ./cmd/blacklist
ssadmin: $(GO_FILES)
$(GO) build -o $@ $(GO_FLAGS) -ldflags "$(GO_LD_FLAGS)" ./cmd/ssadmin

kubeseal: $(GO_FILES)
$(GO) build -o $@ $(GO_FLAGS) -ldflags "$(GO_LD_FLAGS)" ./cmd/kubeseal
Expand All @@ -54,13 +51,10 @@ kubeseal: $(GO_FILES)
docker/controller: controller-static
cp $< $@

docker/trigger: trigger-static
cp $< $@

docker/blacklist: blacklist-static
docker/ssadmin: ssadmin-static
cp $< $@

controller.image: docker/Dockerfile docker/controller docker/trigger docker/blacklist
controller.image: docker/Dockerfile docker/controller docker/ssadmin
$(DOCKER) build -t $(CONTROLLER_IMAGE) docker/
echo $(CONTROLLER_IMAGE) >$@.tmp
mv $@.tmp $@
Expand Down
27 changes: 0 additions & 27 deletions cmd/blacklist/main.go

This file was deleted.

11 changes: 6 additions & 5 deletions cmd/controller/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func writeKeyToKube(client kubernetes.Interface, key *rsa.PrivateKey, cert *x509
return err
}

func createBlacklist(client kubernetes.Interface, r io.Reader, namespace, blacklistName string, keyRegistry *KeyRegistry, trigger func()) (func(string) error, error) {
func createBlacklist(client kubernetes.Interface, r io.Reader, namespace, blacklistName string, keyRegistry *KeyRegistry, trigger func()) (func(string) (bool, error), error) {
privkey, cert, err := newKey(r)
if err != nil {
return nil, err
Expand All @@ -142,21 +142,22 @@ func createBlacklist(client kubernetes.Interface, r io.Reader, namespace, blackl
if _, err := client.Core().Secrets(namespace).Create(blacklist); err != nil {
return nil, err
}
return func(keyName string) error {
return func(keyName string) (bool, error) {
blacklist, err := client.Core().Secrets(namespace).Get(blacklistName, metav1.GetOptions{})
if err != nil {
return err
return false, err
}
blacklist.Data[keyName] = []byte{}
if _, err = client.Core().Secrets(namespace).Update(blacklist); err != nil {
return err
return false, err
}
keyRegistry.blacklistKey(keyName)
// If the latest key is being blacklisted, generate a new key
if keyName == keyRegistry.CurrentKeyName() {
trigger()
return true, nil
}
return nil
return false, nil
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func main2() error {
cnp := func() (string, error) {
return keyRegistry.CurrentKeyName(), nil
}
close, err := triggerserver(blacklister, keyGenTrigger)
close, err := adminserver(blacklister, keyGenTrigger)
if err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions cmd/controller/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@ type secretChecker func([]byte) (bool, error)
type secretRotator func([]byte) ([]byte, error)

// local server functions
type blacklistFunc func(string) error
type blacklistFunc func(string) (bool, error)
type keyGenTrigger func()

func (b blacklistFunc) Blacklist(keyname string, blank *struct{}) error {
return b(keyname)
func (b blacklistFunc) Blacklist(keyname string, generated *bool) error {
gen, err := b(keyname)
*generated = gen
return err
}

func (t keyGenTrigger) Trigger(struct{}, *struct{}) error {
t()
return nil
}

func triggerserver(bl blacklistFunc, kg keyGenTrigger) (func() error, error) {
func adminserver(bl blacklistFunc, kg keyGenTrigger) (func() error, error) {
lis, err := net.Listen("tcp", *localAddr)
if err != nil {
return nil, err
Expand Down
35 changes: 35 additions & 0 deletions cmd/ssadmin/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"flag"
"net"
"net/rpc"
)

var t = false

var (
generateKey = flag.Bool("key-gen", false, "Force controller to generate a new key immediately")
blacklistKeyname = flag.String("blacklist", "", "Give a keyname to blacklist")

generated = &t
)

func main() {
flag.Parse()
conn, err := net.Dial("tcp", ":8081")
if err != nil {
panic(err)
}
client := rpc.NewClient(conn)
if *blacklistKeyname != "" {
if err = client.Call("blacklister.Blacklist", *blacklistKeyname, generated); err != nil {
panic(err)
}
}
if *generateKey && !*generated {
if err = client.Call("trigger.Trigger", struct{}{}, &struct{}{}); err != nil {
panic(err)
}
}
}
17 changes: 0 additions & 17 deletions cmd/trigger/main.go

This file was deleted.

3 changes: 1 addition & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
FROM alpine
MAINTAINER Angus Lees <gus@inodes.org>
COPY controller /usr/local/bin/
COPY trigger /usr/local/bin/
COPY blacklist /usr/local/bin
COPY ssadmin /usr/local/bin/

EXPOSE 8080
EXPOSE 8081
Expand Down
Binary file removed docker/blacklist
Binary file not shown.
Binary file removed docker/trigger
Binary file not shown.

0 comments on commit f173ef9

Please sign in to comment.