@@ -52,7 +52,6 @@ func New(ctx context.Context, options *Options) (*API, error) {
52
52
OIDC : options .OIDCConfig ,
53
53
}
54
54
apiKeyMiddleware := httpmw .ExtractAPIKey (options .Database , oauthConfigs , false )
55
-
56
55
api .AGPL .APIHandler .Group (func (r chi.Router ) {
57
56
r .Get ("/entitlements" , api .serveEntitlements )
58
57
r .Route ("/licenses" , func (r chi.Router ) {
@@ -88,7 +87,9 @@ func New(ctx context.Context, options *Options) (*API, error) {
88
87
type Options struct {
89
88
* coderd.Options
90
89
91
- AuditLogging bool
90
+ AuditLogging bool
91
+ // Whether to block non-browser connections.
92
+ BrowserOnly bool
92
93
SCIMAPIKey []byte
93
94
EntitlementsUpdateInterval time.Duration
94
95
Keys map [string ]ed25519.PublicKey
@@ -107,6 +108,7 @@ type entitlements struct {
107
108
hasLicense bool
108
109
activeUsers codersdk.Feature
109
110
auditLogs codersdk.Entitlement
111
+ browserOnly codersdk.Entitlement
110
112
scim codersdk.Entitlement
111
113
}
112
114
@@ -131,8 +133,9 @@ func (api *API) updateEntitlements(ctx context.Context) error {
131
133
Enabled : false ,
132
134
Entitlement : codersdk .EntitlementNotEntitled ,
133
135
},
134
- auditLogs : codersdk .EntitlementNotEntitled ,
135
- scim : codersdk .EntitlementNotEntitled ,
136
+ auditLogs : codersdk .EntitlementNotEntitled ,
137
+ scim : codersdk .EntitlementNotEntitled ,
138
+ browserOnly : codersdk .EntitlementNotEntitled ,
136
139
}
137
140
138
141
// Here we loop through licenses to detect enabled features.
@@ -165,6 +168,9 @@ func (api *API) updateEntitlements(ctx context.Context) error {
165
168
if claims .Features .AuditLog > 0 {
166
169
entitlements .auditLogs = entitlement
167
170
}
171
+ if claims .Features .BrowserOnly > 0 {
172
+ entitlements .browserOnly = entitlement
173
+ }
168
174
if claims .Features .SCIM > 0 {
169
175
entitlements .scim = entitlement
170
176
}
@@ -174,7 +180,7 @@ func (api *API) updateEntitlements(ctx context.Context) error {
174
180
auditor := agplaudit .NewNop ()
175
181
// A flag could be added to the options that would allow disabling
176
182
// enhanced audit logging here!
177
- if entitlements .auditLogs == codersdk .EntitlementEntitled && api .AuditLogging {
183
+ if entitlements .auditLogs != codersdk .EntitlementNotEntitled && api .AuditLogging {
178
184
auditor = audit .NewAuditor (
179
185
audit .DefaultFilter ,
180
186
backends .NewPostgres (api .Database , true ),
@@ -184,6 +190,14 @@ func (api *API) updateEntitlements(ctx context.Context) error {
184
190
api .AGPL .Auditor .Store (& auditor )
185
191
}
186
192
193
+ if entitlements .browserOnly != api .entitlements .browserOnly {
194
+ var handler func (rw http.ResponseWriter ) bool
195
+ if entitlements .browserOnly != codersdk .EntitlementNotEntitled && api .BrowserOnly {
196
+ handler = api .shouldBlockNonBrowserConnections
197
+ }
198
+ api .AGPL .WorkspaceClientCoordinateOverride .Store (& handler )
199
+ }
200
+
187
201
api .entitlements = entitlements
188
202
189
203
return nil
@@ -230,6 +244,15 @@ func (api *API) serveEntitlements(rw http.ResponseWriter, r *http.Request) {
230
244
"Audit logging is enabled but your license for this feature is expired." )
231
245
}
232
246
247
+ resp .Features [codersdk .FeatureBrowserOnly ] = codersdk.Feature {
248
+ Entitlement : entitlements .browserOnly ,
249
+ Enabled : api .BrowserOnly ,
250
+ }
251
+ if entitlements .browserOnly == codersdk .EntitlementGracePeriod && api .BrowserOnly {
252
+ resp .Warnings = append (resp .Warnings ,
253
+ "Browser only connections are enabled but your license for this feature is expired." )
254
+ }
255
+
233
256
httpapi .Write (ctx , rw , http .StatusOK , resp )
234
257
}
235
258
0 commit comments