-
Notifications
You must be signed in to change notification settings - Fork 2
Run acceptance tests against dev control #11
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| package pkg | ||
|
|
||
| const TSDBCap = "tailscale.com/cap/databases" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| package tailscale | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http/httptest" | ||
| "net/netip" | ||
| "net/url" | ||
| "testing" | ||
|
|
||
| "github.com/tailscale/ts-db-connector/pkg" | ||
| "tailscale.com/client/tailscale/v2" | ||
| "tailscale.com/net/netns" | ||
| "tailscale.com/tailcfg" | ||
| "tailscale.com/tstest/integration" | ||
|
|
@@ -12,7 +19,7 @@ import ( | |
| "tailscale.com/types/logger" | ||
| ) | ||
|
|
||
| func StartControl(t *testing.T) (controlURL string, control *testcontrol.Server) { | ||
| func FakeControlStart(t *testing.T) (controlURL string, control *testcontrol.Server) { | ||
| t.Helper() | ||
|
|
||
| // Corp#4520: don't use netns for tests. | ||
|
|
@@ -63,3 +70,76 @@ func MustInjectFilterRules(t *testing.T, control *testcontrol.Server, nodeKey ke | |
| t.Fatalf("failed to inject raw MapResponse for node with key %s", nodeKey) | ||
| } | ||
| } | ||
|
|
||
| func FakeControlGrantAppCap(t *testing.T, appCaps map[string]any, clientIP netip.Addr, clientNodeKey key.NodePublic, connectorIP netip.Addr, connectorNodeKey key.NodePublic, control *testcontrol.Server) { | ||
| t.Helper() | ||
|
|
||
| rawAppCaps, err := json.Marshal(appCaps) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| filterRules := FormatFilterRules(t, clientIP, connectorIP, rawAppCaps) | ||
| MustInjectFilterRules(t, control, connectorNodeKey, clientNodeKey, filterRules...) | ||
| MustInjectFilterRules(t, control, clientNodeKey, connectorNodeKey) | ||
| } | ||
|
|
||
| func FormatFilterRules(t *testing.T, clientIP netip.Addr, connectorIP netip.Addr, connectorAppCap []byte) []tailcfg.FilterRule { | ||
| t.Helper() | ||
|
|
||
| return []tailcfg.FilterRule{ | ||
| { | ||
| SrcIPs: []string{clientIP.String()}, | ||
| DstPorts: []tailcfg.NetPortRange{ | ||
| { | ||
| IP: fmt.Sprintf("%s/32", connectorIP), | ||
| Ports: tailcfg.PortRange{First: 0, Last: 65535}, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| SrcIPs: []string{clientIP.String()}, | ||
| CapGrant: []tailcfg.CapGrant{{ | ||
| Dsts: []netip.Prefix{ | ||
| netip.MustParsePrefix(fmt.Sprintf("%s/32", connectorIP)), | ||
| }, | ||
| CapMap: tailcfg.PeerCapMap{ | ||
| pkg.TSDBCap: []tailcfg.RawMessage{ | ||
| tailcfg.RawMessage(connectorAppCap), | ||
| }, | ||
| }, | ||
| }}, | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func ControlGrantAppCap(t *testing.T, appCaps map[string]any, controlURL string, apiKey string) { | ||
| t.Helper() | ||
|
|
||
| url, err := url.Parse(controlURL) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| client := &tailscale.Client{ | ||
| BaseURL: url, | ||
| APIKey: apiKey, | ||
| } | ||
|
|
||
| acl := tailscale.ACL{ | ||
| Grants: []tailscale.Grant{ | ||
| { | ||
| Source: []string{"*"}, | ||
| Destination: []string{"*"}, | ||
| IP: []string{"tcp:*"}, | ||
| App: map[string][]map[string]any{ | ||
| pkg.TSDBCap: {appCaps}, | ||
| }, | ||
| }, | ||
| }, | ||
| } | ||
| t.Logf("Overwriting ACL with: %s", acl) | ||
| res, err := client.PolicyFile().SetAndGet(context.Background(), acl, "") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| t.Logf("API response: %s", res) | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd still be keen in a follow-up PR to use our official Go client and to add temporary grant rules instead of overriding the entire policy file. This is dangerous if someone from the community wants to implement a relay and uses its personal tailnet to run the tests.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've created https://github.com/tailscale/corp/issues/34682 to track looking into restoring the grants into their original state. |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍