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

Add MATCH_SUPERSET and MATCH_ANY to SPIRE Server agent endpoints #2468

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ require (
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect
github.com/sirupsen/logrus v1.4.2
github.com/spiffe/go-spiffe/v2 v2.0.0-beta.6
github.com/spiffe/spire-api-sdk v1.0.0
github.com/spiffe/spire-api-sdk v1.0.2-0.20210816212232-782cd5a6b660
github.com/spiffe/spire-plugin-sdk v1.0.0
github.com/stretchr/testify v1.7.0
github.com/uber-go/tally v3.3.12+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,8 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/spiffe/go-spiffe/v2 v2.0.0-beta.6 h1:3DOMziVxNur7Gq7JkfJg5sLZbbtfkBi13SlDfByV9YI=
github.com/spiffe/go-spiffe/v2 v2.0.0-beta.6/go.mod h1:TEfgrEcyFhuSuvqohJt6IxENUNeHfndWCCV1EX7UaVk=
github.com/spiffe/spire-api-sdk v1.0.0 h1:swo8bFdEPNmXjpX72eudbyboq1wMrp/oPH7GCMjOaSY=
github.com/spiffe/spire-api-sdk v1.0.0/go.mod h1:2wSTZ6oEnKqI3uBST05Mmm751+yoHEvgxomYKYOQ6Ko=
github.com/spiffe/spire-api-sdk v1.0.2-0.20210816212232-782cd5a6b660 h1:/QgMFt0sZRzYoa07t6vmvlTShI46p2ZCe64VnM3yD3Q=
github.com/spiffe/spire-api-sdk v1.0.2-0.20210816212232-782cd5a6b660/go.mod h1:2wSTZ6oEnKqI3uBST05Mmm751+yoHEvgxomYKYOQ6Ko=
github.com/spiffe/spire-plugin-sdk v1.0.0 h1:Y5oWPvWS2S+BT9pIKP6fjPXIFLFfARqbIcxp0gjyYls=
github.com/spiffe/spire-plugin-sdk v1.0.0/go.mod h1:fzNSP83Z848jZtPQYeZ9qPWZkbSPwmd/JFNux1gxsbM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
248 changes: 248 additions & 0 deletions pkg/server/api/agent/v1/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,254 @@ func TestListAgents(t *testing.T) {
},
},
},
{
name: "by selectors - match any",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_ANY,
Selectors: []*types.Selector{
{Type: "a", Value: "1"},
{Type: "b", Value: "2"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{
{Id: api.ProtoFromID(node1ID)},
{Id: api.ProtoFromID(node2ID)},
},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_ANY",
telemetry.BySelectors: "a:1,b:2",
},
},
},
},
{
name: "by selectors - match any (no results)",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_ANY,
Selectors: []*types.Selector{
{Type: "d", Value: "2"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_ANY",
telemetry.BySelectors: "d:2",
},
},
},
},
{
name: "by selectors - match exact",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_EXACT,
Selectors: []*types.Selector{
{Type: "a", Value: "1"},
{Type: "b", Value: "2"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{
{Id: api.ProtoFromID(node1ID)},
},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_EXACT",
telemetry.BySelectors: "a:1,b:2",
},
},
},
},
{
name: "by selectors - match exact (no results)",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_EXACT,
Selectors: []*types.Selector{
{Type: "b", Value: "2"},
{Type: "c", Value: "3"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_EXACT",
telemetry.BySelectors: "b:2,c:3",
},
},
},
},
{
name: "by selectors - match subset",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_SUBSET,
Selectors: []*types.Selector{
{Type: "a", Value: "1"},
{Type: "c", Value: "3"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{
{Id: api.ProtoFromID(node2ID)},
},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_SUBSET",
telemetry.BySelectors: "a:1,c:3",
},
},
},
},
{
name: "by selectors - match subset (no results)",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_SUBSET,
Selectors: []*types.Selector{
{Type: "b", Value: "2"},
{Type: "c", Value: "3"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_SUBSET",
telemetry.BySelectors: "b:2,c:3",
},
},
},
},
{
name: "by selectors - match superset",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_SUPERSET,
Selectors: []*types.Selector{
{Type: "a", Value: "1"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{
{Id: api.ProtoFromID(node1ID)},
{Id: api.ProtoFromID(node2ID)},
},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_SUPERSET",
telemetry.BySelectors: "a:1",
},
},
},
},
{
name: "by selectors - match superset (no results)",
req: &agentv1.ListAgentsRequest{
OutputMask: &types.AgentMask{},
Filter: &agentv1.ListAgentsRequest_Filter{
BySelectorMatch: &types.SelectorMatch{
Match: types.SelectorMatch_MATCH_SUPERSET,
Selectors: []*types.Selector{
{Type: "b", Value: "2"},
{Type: "c", Value: "3"},
},
},
},
},
expectResp: &agentv1.ListAgentsResponse{
Agents: []*types.Agent{},
},
expectLogs: []spiretest.LogEntry{
{
Level: logrus.InfoLevel,
Message: "API accessed",
Data: logrus.Fields{
telemetry.Status: "success",
telemetry.Type: "audit",
telemetry.BySelectorMatch: "MATCH_SUPERSET",
telemetry.BySelectors: "b:2,c:3",
},
},
},
},
{
name: "with pagination",
req: &agentv1.ListAgentsRequest{
Expand Down