Skip to content
This repository has been archived by the owner on Jul 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #32 from zlabjp/follow-spire-1.0
Browse files Browse the repository at this point in the history
Follow spire 1.0
  • Loading branch information
hiyosi committed Sep 14, 2021
2 parents b03adc9 + 13c9c16 commit b08bd3f
Show file tree
Hide file tree
Showing 17 changed files with 1,387 additions and 531 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on: [push]
name: Golang Tests
jobs:
test:
strategy:
matrix:
go-version: [1.16.x]
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Vet
run: go vet ./...
- name: Test
run: make test
- name: Build
run: make build
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prerequisites

- Go 1.14 or higher
- Go 1.16 or higher

## Building

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ build-darwin: OS=darwin
build-darwin: build

$(binary_dirs): clean
cd cmd/$@ && GOOS=$(OS) GOARCH=amd64 go build -o ../../../$(out_dir)/$@ -i
cd cmd/$@ && GOOS=$(OS) GOARCH=amd64 go build -o ../../../$(out_dir)/$@

test:
go test -race ./cmd/... ./pkg/...
Expand Down
46 changes: 19 additions & 27 deletions cmd/agent/openstack_iid_attestor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,34 @@ import (
"fmt"

"github.com/hashicorp/go-hclog"
"github.com/spiffe/spire/pkg/agent/plugin/nodeattestor"
"github.com/spiffe/spire/pkg/common/catalog"
spc "github.com/spiffe/spire/proto/spire/common"
spi "github.com/spiffe/spire/proto/spire/common/plugin"
"github.com/spiffe/spire-plugin-sdk/pluginmain"
nodeattestorv1 "github.com/spiffe/spire-plugin-sdk/proto/spire/plugin/agent/nodeattestor/v1"
configv1 "github.com/spiffe/spire-plugin-sdk/proto/spire/service/common/config/v1"

"github.com/zlabjp/spire-openstack-plugin/pkg/common"
"github.com/zlabjp/spire-openstack-plugin/pkg/openstack"
)

// IIDAttestorPlugin implements the nodeattestor Plugin interface
type IIDAttestorPlugin struct {
nodeattestorv1.UnsafeNodeAttestorServer
configv1.UnsafeConfigServer

logger hclog.Logger

getMetadataHandler func() (*openstack.Metadata, error)
}

// BuiltIn constructs a catalog Plugin using a new instance of this plugin.
func BuiltIn() catalog.Plugin {
return builtin(New())
}

func builtin(p *IIDAttestorPlugin) catalog.Plugin {
return catalog.MakePlugin(common.PluginName, nodeattestor.PluginServer(p))
}

func New() *IIDAttestorPlugin {
func newPlugin() *IIDAttestorPlugin {
return &IIDAttestorPlugin{
getMetadataHandler: openstack.GetMetadataFromMetadataService,
}
}

func (p *IIDAttestorPlugin) Configure(ctx context.Context, req *spi.ConfigureRequest) (*spi.ConfigureResponse, error) {
return &spi.ConfigureResponse{}, nil
}

func (p *IIDAttestorPlugin) GetPluginInfo(context.Context, *spi.GetPluginInfoRequest) (*spi.GetPluginInfoResponse, error) {
return &spi.GetPluginInfoResponse{}, nil
func (p *IIDAttestorPlugin) Configure(_ context.Context, _ *configv1.ConfigureRequest) (*configv1.ConfigureResponse, error) {
return &configv1.ConfigureResponse{}, nil
}

func (p *IIDAttestorPlugin) FetchAttestationData(stream nodeattestor.NodeAttestor_FetchAttestationDataServer) error {
func (p *IIDAttestorPlugin) AidAttestation(stream nodeattestorv1.NodeAttestor_AidAttestationServer) error {
p.logger.Info("Prepare Attestation Request")

if p.getMetadataHandler == nil {
Expand All @@ -63,10 +51,10 @@ func (p *IIDAttestorPlugin) FetchAttestationData(stream nodeattestor.NodeAttesto
if err != nil {
return fmt.Errorf("failed to retrieve openstack metadata: %v", err)
}
return stream.Send(&nodeattestor.FetchAttestationDataResponse{
AttestationData: &spc.AttestationData{
Type: common.PluginName,
Data: []byte(meta.UUID),

return stream.Send(&nodeattestorv1.PayloadOrChallengeResponse{
Data: &nodeattestorv1.PayloadOrChallengeResponse_Payload{
Payload: []byte(meta.UUID),
},
})
}
Expand All @@ -76,5 +64,9 @@ func (p *IIDAttestorPlugin) SetLogger(log hclog.Logger) {
}

func main() {
catalog.PluginMain(BuiltIn())
p := newPlugin()
pluginmain.Serve(
nodeattestorv1.NodeAttestorPluginServer(p),
configv1.ConfigServiceServer(p),
)
}
16 changes: 8 additions & 8 deletions cmd/agent/openstack_iid_attestor/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

"github.com/zlabjp/spire-openstack-plugin/pkg/openstack"
"github.com/zlabjp/spire-openstack-plugin/pkg/testutil"
"github.com/zlabjp/spire-openstack-plugin/pkg/util/fake"
fake_agent "github.com/zlabjp/spire-openstack-plugin/pkg/testutil/fake/agent"
)

func newTestPlugin() *IIDAttestorPlugin {
Expand All @@ -23,7 +23,7 @@ func newTestPlugin() *IIDAttestorPlugin {
}
}

func TestFetchAttestationData(t *testing.T) {
func TestAidAttestation(t *testing.T) {
p := newTestPlugin()
p.getMetadataHandler = func() (*openstack.Metadata, error) {
return &openstack.Metadata{
Expand All @@ -33,9 +33,9 @@ func TestFetchAttestationData(t *testing.T) {
}, nil
}

f := fake.NewFakeFetchAttestationStream()
f := fake_agent.NewAidAttestationStream()

if err := p.FetchAttestationData(f); err != nil {
if err := p.AidAttestation(f); err != nil {
t.Errorf("unexpected error from FetchAttestationData(): %v", err)
}
if _, err := f.Recv(); err != nil {
Expand All @@ -50,10 +50,10 @@ func TestFetchAttestationDataMetadataHandlerFailed(t *testing.T) {
return nil, errors.New(errMsg)
}

f := fake.NewFakeFetchAttestationStream()
f := fake_agent.NewAidAttestationStream()
wantErr := fmt.Sprintf("failed to retrieve openstack metadata: %v", errMsg)

if err := p.FetchAttestationData(f); err == nil {
if err := p.AidAttestation(f); err == nil {
t.Errorf("Expected an error, got nil: %v", err)
} else {
if err.Error() != wantErr {
Expand All @@ -68,9 +68,9 @@ func TestFetchAttestationDataMetadataHandlerNotFound(t *testing.T) {

errMsg := "handler not found, plugin not initialized"

f := fake.NewFakeFetchAttestationStream()
f := fake_agent.NewAidAttestationStream()

err := p.FetchAttestationData(f)
err := p.AidAttestation(f)
if err == nil {
t.Error("expected an error is occurred but got nil")
} else {
Expand Down
Loading

0 comments on commit b08bd3f

Please sign in to comment.