Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ func NewHandler(cfg Config, opts ...HandlerOption) (*APIHandler, error) {
// part[0] is empty space from leading slash "/"
// part[1] is the prefix "v1"
switch pathParts[2] {
case "webapi", "enterprise", "scripts", ".well-known", "workload-identity":
case "webapi", "enterprise", "scripts", ".well-known", "workload-identity", "web":
http.StripPrefix(v1Prefix, h).ServeHTTP(w, r)
return
}
Expand Down Expand Up @@ -1946,7 +1946,7 @@ func setEntitlementsWithLegacyLogic(webCfg *webclient.WebConfig, clusterFeatures
// set default Identity fields to legacy feature value
webCfg.Entitlements[string(entitlements.AccessLists)] = webclient.EntitlementInfo{Enabled: true, Limit: clusterFeatures.GetAccessList().GetCreateLimit()}
webCfg.Entitlements[string(entitlements.AccessMonitoring)] = webclient.EntitlementInfo{Enabled: clusterFeatures.GetAccessMonitoring().GetEnabled(), Limit: clusterFeatures.GetAccessMonitoring().GetMaxReportRangeLimit()}
webCfg.Entitlements[string(entitlements.AccessRequests)] = webclient.EntitlementInfo{Enabled: clusterFeatures.GetAccessRequests().MonthlyRequestLimit > 0, Limit: clusterFeatures.GetAccessRequests().GetMonthlyRequestLimit()}
webCfg.Entitlements[string(entitlements.AccessRequests)] = webclient.EntitlementInfo{Enabled: clusterFeatures.GetAccessRequests().GetMonthlyRequestLimit() > 0, Limit: clusterFeatures.GetAccessRequests().GetMonthlyRequestLimit()}
webCfg.Entitlements[string(entitlements.DeviceTrust)] = webclient.EntitlementInfo{Enabled: clusterFeatures.GetDeviceTrust().GetEnabled(), Limit: clusterFeatures.GetDeviceTrust().GetDevicesUsageLimit()}
// override Identity Package features if Identity is enabled: set true and clear limit
if clusterFeatures.GetIdentityGovernance() {
Expand All @@ -1960,7 +1960,7 @@ func setEntitlementsWithLegacyLogic(webCfg *webclient.WebConfig, clusterFeatures
}

// webCfg.<legacy fields>: set equal to legacy feature value
webCfg.AccessRequests = clusterFeatures.GetAccessRequests().MonthlyRequestLimit > 0
webCfg.AccessRequests = clusterFeatures.GetAccessRequests().GetMonthlyRequestLimit() > 0
webCfg.ExternalAuditStorage = clusterFeatures.GetExternalAuditStorage()
webCfg.HideInaccessibleFeatures = clusterFeatures.GetFeatureHiding()
webCfg.IsIGSEnabled = clusterFeatures.GetIdentityGovernance()
Expand Down
83 changes: 83 additions & 0 deletions lib/web/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3585,6 +3585,89 @@ func TestEndpointNotFoundHandling(t *testing.T) {
}
}

func TestKnownWebPathsWithAndWithoutV1Prefix(t *testing.T) {
t.Parallel()
const username = "test-user@example.com"
// Allow user to create tokens.
roleTokenCRD, err := types.NewRole(services.RoleNameForUser(username), types.RoleSpecV6{
Allow: types.RoleConditions{
Rules: []types.Rule{
types.NewRule(types.KindToken,
[]string{types.VerbCreate}),
},
},
})
require.NoError(t, err)

env := newWebPack(t, 1)
proxy := env.proxies[0]
pack := proxy.authPack(t, username, []types.Role{roleTokenCRD})

res, err := pack.clt.PostJSON(context.Background(), pack.clt.Endpoint("webapi", "token"), types.ProvisionTokenSpecV2{
Roles: types.SystemRoles{types.RoleNode},
})
require.NoError(t, err)

var responseToken nodeJoinToken
err = json.Unmarshal(res.Bytes(), &responseToken)
require.NoError(t, err)

tt := []struct {
name string
endpoint string
}{
{
name: "web path with prefix",
endpoint: "v1/web/config.js",
},
{
name: "web path without prefix",
endpoint: "web/config.js",
},
{
name: "webapi path with prefix",
endpoint: "v1/webapi/spiffe/bundle.json",
},
{
name: "webapi path without prefix",
endpoint: "webapi/spiffe/bundle.json",
},
{
name: ".well-known path with prefix",
endpoint: "v1/.well-known/jwks.json",
},
{
name: ".well-known path without prefix",
endpoint: ".well-known/jwks.json",
},
{
name: "workload-identity path with prefix",
endpoint: "v1/workload-identity/jwt-jwks.json",
},
{
name: "workload-identity path without prefix",
endpoint: "workload-identity/jwt-jwks.json",
},
{
name: "scripts path with prefix",
endpoint: fmt.Sprintf("v1/scripts/%s/install-node.sh", responseToken.ID),
},
{
name: "scripts path without prefix",
endpoint: fmt.Sprintf("scripts/%s/install-node.sh", responseToken.ID),
},
}

for _, tc := range tt {
tc := tc
t.Run(tc.name, func(t *testing.T) {
_, err := pack.clt.Get(context.Background(), fmt.Sprintf("%s/%s", proxy.web.URL, tc.endpoint), url.Values{})

require.NoError(t, err)
})
}
}

func TestInstallDatabaseScriptGeneration(t *testing.T) {
const username = "test-user@example.com"

Expand Down