@@ -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 ) {
@@ -75,7 +74,9 @@ func New(ctx context.Context, options *Options) (*API, error) {
75
74
type Options struct {
76
75
* coderd.Options
77
76
78
- AuditLogging bool
77
+ AuditLogging bool
78
+ // Whether to block non-browser connections.
79
+ BrowserOnly bool
79
80
EntitlementsUpdateInterval time.Duration
80
81
Keys map [string ]ed25519.PublicKey
81
82
}
@@ -93,6 +94,7 @@ type entitlements struct {
93
94
hasLicense bool
94
95
activeUsers codersdk.Feature
95
96
auditLogs codersdk.Entitlement
97
+ browserOnly codersdk.Entitlement
96
98
}
97
99
98
100
func (api * API ) Close () error {
@@ -149,13 +151,16 @@ func (api *API) updateEntitlements(ctx context.Context) error {
149
151
if claims .Features .AuditLog > 0 {
150
152
entitlements .auditLogs = entitlement
151
153
}
154
+ if claims .Features .BrowserOnly > 0 {
155
+ entitlements .browserOnly = entitlement
156
+ }
152
157
}
153
158
154
159
if entitlements .auditLogs != api .entitlements .auditLogs {
155
160
auditor := agplaudit .NewNop ()
156
161
// A flag could be added to the options that would allow disabling
157
162
// enhanced audit logging here!
158
- if entitlements .auditLogs == codersdk .EntitlementEntitled && api .AuditLogging {
163
+ if entitlements .auditLogs != codersdk .EntitlementNotEntitled && api .AuditLogging {
159
164
auditor = audit .NewAuditor (
160
165
audit .DefaultFilter ,
161
166
backends .NewPostgres (api .Database , true ),
@@ -165,6 +170,14 @@ func (api *API) updateEntitlements(ctx context.Context) error {
165
170
api .AGPL .Auditor .Store (& auditor )
166
171
}
167
172
173
+ if entitlements .browserOnly != api .entitlements .browserOnly {
174
+ var handler func (rw http.ResponseWriter ) bool
175
+ if entitlements .browserOnly != codersdk .EntitlementNotEntitled && api .BrowserOnly {
176
+ handler = api .shouldBlockNonBrowserConnections
177
+ }
178
+ api .AGPL .WorkspaceClientCoordinateOverride .Store (& handler )
179
+ }
180
+
168
181
api .entitlements = entitlements
169
182
170
183
return nil
@@ -210,6 +223,15 @@ func (api *API) serveEntitlements(rw http.ResponseWriter, r *http.Request) {
210
223
"Audit logging is enabled but your license for this feature is expired." )
211
224
}
212
225
226
+ resp .Features [codersdk .FeatureBrowserOnly ] = codersdk.Feature {
227
+ Entitlement : entitlements .browserOnly ,
228
+ Enabled : api .BrowserOnly ,
229
+ }
230
+ if entitlements .browserOnly == codersdk .EntitlementGracePeriod && api .BrowserOnly {
231
+ resp .Warnings = append (resp .Warnings ,
232
+ "Browser only connections are enabled but your license for this feature is expired." )
233
+ }
234
+
213
235
httpapi .Write (rw , http .StatusOK , resp )
214
236
}
215
237
0 commit comments