util/syspolicy/*: move syspolicy keys to new const leaf "pkey" package
This is step 1 of ~3, breaking up #14720 into reviewable chunks, with the aim to make syspolicy be a build-time configurable feature. In this first (very noisy) step, all the syspolicy string key constants move to a new constant-only (code-free) package. This will make future steps more reviewable, without this movement noise. There are no code or behavior changes here. The future steps of this series can be seen in #14720: removing global funcs from syspolicy resolution and using an interface that's plumbed around instead. Then adding build tags. Updates #12614 Change-Id: If73bf2c28b9c9b1a408fe868b0b6a25b03eeabd1 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
6d45fcfc93
commit
cc532efc20
+59
-58
@@ -62,6 +62,7 @@ import (
|
||||
"tailscale.com/util/must"
|
||||
"tailscale.com/util/set"
|
||||
"tailscale.com/util/syspolicy"
|
||||
"tailscale.com/util/syspolicy/pkey"
|
||||
"tailscale.com/util/syspolicy/setting"
|
||||
"tailscale.com/util/syspolicy/source"
|
||||
"tailscale.com/wgengine"
|
||||
@@ -1182,16 +1183,16 @@ func TestConfigureExitNode(t *testing.T) {
|
||||
// Configure policy settings, if any.
|
||||
store := source.NewTestStore(t)
|
||||
if tt.exitNodeIDPolicy != nil {
|
||||
store.SetStrings(source.TestSettingOf(syspolicy.ExitNodeID, string(*tt.exitNodeIDPolicy)))
|
||||
store.SetStrings(source.TestSettingOf(pkey.ExitNodeID, string(*tt.exitNodeIDPolicy)))
|
||||
}
|
||||
if tt.exitNodeIPPolicy != nil {
|
||||
store.SetStrings(source.TestSettingOf(syspolicy.ExitNodeIP, tt.exitNodeIPPolicy.String()))
|
||||
store.SetStrings(source.TestSettingOf(pkey.ExitNodeIP, tt.exitNodeIPPolicy.String()))
|
||||
}
|
||||
if tt.exitNodeAllowedIDs != nil {
|
||||
store.SetStringLists(source.TestSettingOf(syspolicy.AllowedSuggestedExitNodes, toStrings(tt.exitNodeAllowedIDs)))
|
||||
store.SetStringLists(source.TestSettingOf(pkey.AllowedSuggestedExitNodes, toStrings(tt.exitNodeAllowedIDs)))
|
||||
}
|
||||
if tt.exitNodeAllowOverride {
|
||||
store.SetBooleans(source.TestSettingOf(syspolicy.AllowExitNodeOverride, true))
|
||||
store.SetBooleans(source.TestSettingOf(pkey.AllowExitNodeOverride, true))
|
||||
}
|
||||
if store.IsEmpty() {
|
||||
// No syspolicy settings, so don't register a store.
|
||||
@@ -2890,10 +2891,10 @@ func TestSetExitNodeIDPolicy(t *testing.T) {
|
||||
|
||||
policyStore := source.NewTestStore(t)
|
||||
if test.exitNodeIDKey {
|
||||
policyStore.SetStrings(source.TestSettingOf(syspolicy.ExitNodeID, test.exitNodeID))
|
||||
policyStore.SetStrings(source.TestSettingOf(pkey.ExitNodeID, test.exitNodeID))
|
||||
}
|
||||
if test.exitNodeIPKey {
|
||||
policyStore.SetStrings(source.TestSettingOf(syspolicy.ExitNodeIP, test.exitNodeIP))
|
||||
policyStore.SetStrings(source.TestSettingOf(pkey.ExitNodeIP, test.exitNodeIP))
|
||||
}
|
||||
syspolicy.MustRegisterStoreForTest(t, "TestStore", setting.DeviceScope, policyStore)
|
||||
|
||||
@@ -3029,7 +3030,7 @@ func TestUpdateNetmapDeltaAutoExitNode(t *testing.T) {
|
||||
|
||||
syspolicy.RegisterWellKnownSettingsForTest(t)
|
||||
policyStore := source.NewTestStoreOf(t, source.TestSettingOf(
|
||||
syspolicy.ExitNodeID, "auto:any",
|
||||
pkey.ExitNodeID, "auto:any",
|
||||
))
|
||||
syspolicy.MustRegisterStoreForTest(t, "TestStore", setting.DeviceScope, policyStore)
|
||||
|
||||
@@ -3114,7 +3115,7 @@ func TestAutoExitNodeSetNetInfoCallback(t *testing.T) {
|
||||
b.cc = cc
|
||||
syspolicy.RegisterWellKnownSettingsForTest(t)
|
||||
policyStore := source.NewTestStoreOf(t, source.TestSettingOf(
|
||||
syspolicy.ExitNodeID, "auto:any",
|
||||
pkey.ExitNodeID, "auto:any",
|
||||
))
|
||||
syspolicy.MustRegisterStoreForTest(t, "TestStore", setting.DeviceScope, policyStore)
|
||||
peer1 := makePeer(1, withCap(26), withDERP(3), withSuggest(), withExitRoutes())
|
||||
@@ -3223,7 +3224,7 @@ func TestSetControlClientStatusAutoExitNode(t *testing.T) {
|
||||
b := newTestLocalBackend(t)
|
||||
syspolicy.RegisterWellKnownSettingsForTest(t)
|
||||
policyStore := source.NewTestStoreOf(t, source.TestSettingOf(
|
||||
syspolicy.ExitNodeID, "auto:any",
|
||||
pkey.ExitNodeID, "auto:any",
|
||||
))
|
||||
syspolicy.MustRegisterStoreForTest(t, "TestStore", setting.DeviceScope, policyStore)
|
||||
b.currentNode().SetNetMap(nm)
|
||||
@@ -3255,7 +3256,7 @@ func TestApplySysPolicy(t *testing.T) {
|
||||
prefs ipn.Prefs
|
||||
wantPrefs ipn.Prefs
|
||||
wantAnyChange bool
|
||||
stringPolicies map[syspolicy.Key]string
|
||||
stringPolicies map[pkey.Key]string
|
||||
}{
|
||||
{
|
||||
name: "empty prefs without policies",
|
||||
@@ -3290,13 +3291,13 @@ func TestApplySysPolicy(t *testing.T) {
|
||||
RouteAll: true,
|
||||
},
|
||||
wantAnyChange: true,
|
||||
stringPolicies: map[syspolicy.Key]string{
|
||||
syspolicy.ControlURL: "1",
|
||||
syspolicy.EnableIncomingConnections: "never",
|
||||
syspolicy.EnableServerMode: "always",
|
||||
syspolicy.ExitNodeAllowLANAccess: "always",
|
||||
syspolicy.EnableTailscaleDNS: "always",
|
||||
syspolicy.EnableTailscaleSubnets: "always",
|
||||
stringPolicies: map[pkey.Key]string{
|
||||
pkey.ControlURL: "1",
|
||||
pkey.EnableIncomingConnections: "never",
|
||||
pkey.EnableServerMode: "always",
|
||||
pkey.ExitNodeAllowLANAccess: "always",
|
||||
pkey.EnableTailscaleDNS: "always",
|
||||
pkey.EnableTailscaleSubnets: "always",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -3311,13 +3312,13 @@ func TestApplySysPolicy(t *testing.T) {
|
||||
ShieldsUp: true,
|
||||
ForceDaemon: true,
|
||||
},
|
||||
stringPolicies: map[syspolicy.Key]string{
|
||||
syspolicy.ControlURL: "1",
|
||||
syspolicy.EnableIncomingConnections: "never",
|
||||
syspolicy.EnableServerMode: "always",
|
||||
syspolicy.ExitNodeAllowLANAccess: "never",
|
||||
syspolicy.EnableTailscaleDNS: "never",
|
||||
syspolicy.EnableTailscaleSubnets: "never",
|
||||
stringPolicies: map[pkey.Key]string{
|
||||
pkey.ControlURL: "1",
|
||||
pkey.EnableIncomingConnections: "never",
|
||||
pkey.EnableServerMode: "always",
|
||||
pkey.ExitNodeAllowLANAccess: "never",
|
||||
pkey.EnableTailscaleDNS: "never",
|
||||
pkey.EnableTailscaleSubnets: "never",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -3339,13 +3340,13 @@ func TestApplySysPolicy(t *testing.T) {
|
||||
RouteAll: true,
|
||||
},
|
||||
wantAnyChange: true,
|
||||
stringPolicies: map[syspolicy.Key]string{
|
||||
syspolicy.ControlURL: "2",
|
||||
syspolicy.EnableIncomingConnections: "always",
|
||||
syspolicy.EnableServerMode: "never",
|
||||
syspolicy.ExitNodeAllowLANAccess: "always",
|
||||
syspolicy.EnableTailscaleDNS: "never",
|
||||
syspolicy.EnableTailscaleSubnets: "always",
|
||||
stringPolicies: map[pkey.Key]string{
|
||||
pkey.ControlURL: "2",
|
||||
pkey.EnableIncomingConnections: "always",
|
||||
pkey.EnableServerMode: "never",
|
||||
pkey.ExitNodeAllowLANAccess: "always",
|
||||
pkey.EnableTailscaleDNS: "never",
|
||||
pkey.EnableTailscaleSubnets: "always",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -3366,12 +3367,12 @@ func TestApplySysPolicy(t *testing.T) {
|
||||
CorpDNS: true,
|
||||
RouteAll: true,
|
||||
},
|
||||
stringPolicies: map[syspolicy.Key]string{
|
||||
syspolicy.EnableIncomingConnections: "user-decides",
|
||||
syspolicy.EnableServerMode: "user-decides",
|
||||
syspolicy.ExitNodeAllowLANAccess: "user-decides",
|
||||
syspolicy.EnableTailscaleDNS: "user-decides",
|
||||
syspolicy.EnableTailscaleSubnets: "user-decides",
|
||||
stringPolicies: map[pkey.Key]string{
|
||||
pkey.EnableIncomingConnections: "user-decides",
|
||||
pkey.EnableServerMode: "user-decides",
|
||||
pkey.ExitNodeAllowLANAccess: "user-decides",
|
||||
pkey.EnableTailscaleDNS: "user-decides",
|
||||
pkey.EnableTailscaleSubnets: "user-decides",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -3380,8 +3381,8 @@ func TestApplySysPolicy(t *testing.T) {
|
||||
ControlURL: "set",
|
||||
},
|
||||
wantAnyChange: true,
|
||||
stringPolicies: map[syspolicy.Key]string{
|
||||
syspolicy.ControlURL: "set",
|
||||
stringPolicies: map[pkey.Key]string{
|
||||
pkey.ControlURL: "set",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -3399,8 +3400,8 @@ func TestApplySysPolicy(t *testing.T) {
|
||||
},
|
||||
},
|
||||
wantAnyChange: true,
|
||||
stringPolicies: map[syspolicy.Key]string{
|
||||
syspolicy.ApplyUpdates: "always",
|
||||
stringPolicies: map[pkey.Key]string{
|
||||
pkey.ApplyUpdates: "always",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -3418,8 +3419,8 @@ func TestApplySysPolicy(t *testing.T) {
|
||||
},
|
||||
},
|
||||
wantAnyChange: true,
|
||||
stringPolicies: map[syspolicy.Key]string{
|
||||
syspolicy.ApplyUpdates: "never",
|
||||
stringPolicies: map[pkey.Key]string{
|
||||
pkey.ApplyUpdates: "never",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -3437,8 +3438,8 @@ func TestApplySysPolicy(t *testing.T) {
|
||||
},
|
||||
},
|
||||
wantAnyChange: true,
|
||||
stringPolicies: map[syspolicy.Key]string{
|
||||
syspolicy.CheckUpdates: "always",
|
||||
stringPolicies: map[pkey.Key]string{
|
||||
pkey.CheckUpdates: "always",
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -3456,8 +3457,8 @@ func TestApplySysPolicy(t *testing.T) {
|
||||
},
|
||||
},
|
||||
wantAnyChange: true,
|
||||
stringPolicies: map[syspolicy.Key]string{
|
||||
syspolicy.CheckUpdates: "never",
|
||||
stringPolicies: map[pkey.Key]string{
|
||||
pkey.CheckUpdates: "never",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -5574,7 +5575,7 @@ func TestFillAllowedSuggestions(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
policyStore := source.NewTestStoreOf(t, source.TestSettingOf(
|
||||
syspolicy.AllowedSuggestedExitNodes, tt.allowPolicy,
|
||||
pkey.AllowedSuggestedExitNodes, tt.allowPolicy,
|
||||
))
|
||||
syspolicy.MustRegisterStoreForTest(t, "TestStore", setting.DeviceScope, policyStore)
|
||||
|
||||
@@ -6480,23 +6481,23 @@ func TestUpdatePrefsOnSysPolicyChange(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "ShieldsUp/True",
|
||||
stringSettings: []source.TestSetting[string]{source.TestSettingOf(syspolicy.EnableIncomingConnections, "never")},
|
||||
stringSettings: []source.TestSetting[string]{source.TestSettingOf(pkey.EnableIncomingConnections, "never")},
|
||||
want: wantPrefsChanges(fieldChange{"ShieldsUp", true}),
|
||||
},
|
||||
{
|
||||
name: "ShieldsUp/False",
|
||||
initialPrefs: &ipn.Prefs{ShieldsUp: true},
|
||||
stringSettings: []source.TestSetting[string]{source.TestSettingOf(syspolicy.EnableIncomingConnections, "always")},
|
||||
stringSettings: []source.TestSetting[string]{source.TestSettingOf(pkey.EnableIncomingConnections, "always")},
|
||||
want: wantPrefsChanges(fieldChange{"ShieldsUp", false}),
|
||||
},
|
||||
{
|
||||
name: "ExitNodeID",
|
||||
stringSettings: []source.TestSetting[string]{source.TestSettingOf(syspolicy.ExitNodeID, "foo")},
|
||||
stringSettings: []source.TestSetting[string]{source.TestSettingOf(pkey.ExitNodeID, "foo")},
|
||||
want: wantPrefsChanges(fieldChange{"ExitNodeID", tailcfg.StableNodeID("foo")}),
|
||||
},
|
||||
{
|
||||
name: "EnableRunExitNode",
|
||||
stringSettings: []source.TestSetting[string]{source.TestSettingOf(syspolicy.EnableRunExitNode, "always")},
|
||||
stringSettings: []source.TestSetting[string]{source.TestSettingOf(pkey.EnableRunExitNode, "always")},
|
||||
want: wantPrefsChanges(fieldChange{"AdvertiseRoutes", []netip.Prefix{tsaddr.AllIPv4(), tsaddr.AllIPv6()}}),
|
||||
},
|
||||
{
|
||||
@@ -6505,9 +6506,9 @@ func TestUpdatePrefsOnSysPolicyChange(t *testing.T) {
|
||||
ExitNodeAllowLANAccess: true,
|
||||
},
|
||||
stringSettings: []source.TestSetting[string]{
|
||||
source.TestSettingOf(syspolicy.EnableServerMode, "always"),
|
||||
source.TestSettingOf(syspolicy.ExitNodeAllowLANAccess, "never"),
|
||||
source.TestSettingOf(syspolicy.ExitNodeIP, "127.0.0.1"),
|
||||
source.TestSettingOf(pkey.EnableServerMode, "always"),
|
||||
source.TestSettingOf(pkey.ExitNodeAllowLANAccess, "never"),
|
||||
source.TestSettingOf(pkey.ExitNodeIP, "127.0.0.1"),
|
||||
},
|
||||
want: wantPrefsChanges(
|
||||
fieldChange{"ForceDaemon", true},
|
||||
@@ -6523,9 +6524,9 @@ func TestUpdatePrefsOnSysPolicyChange(t *testing.T) {
|
||||
AdvertiseRoutes: []netip.Prefix{tsaddr.AllIPv4(), tsaddr.AllIPv6()},
|
||||
},
|
||||
stringSettings: []source.TestSetting[string]{
|
||||
source.TestSettingOf(syspolicy.EnableTailscaleDNS, "always"),
|
||||
source.TestSettingOf(syspolicy.ExitNodeID, "foo"),
|
||||
source.TestSettingOf(syspolicy.EnableRunExitNode, "always"),
|
||||
source.TestSettingOf(pkey.EnableTailscaleDNS, "always"),
|
||||
source.TestSettingOf(pkey.ExitNodeID, "foo"),
|
||||
source.TestSettingOf(pkey.EnableRunExitNode, "always"),
|
||||
},
|
||||
want: nil, // syspolicy settings match the preferences; no change notification is expected.
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user