Debian Codegraph @

internal/config/flags.go

raw
1 package config
2
3 import (
4 "flag"
5 )
6
7 //goland:noinspection GoMixedReceiverTypes
8 func (c *Config) flagSetDebug(flagSet *flag.FlagSet) {
9 flagSet.BoolVar(
10 &c.Debug.Pprof,
11 "debug.pprof",
12 c.Debug.Pprof,
13 "Enables go profiling endpoint. This should be never exposed.",
14 )
15 flagSet.StringVar(
16 &c.Debug.Listen,
17 "debug.listen",
18 c.Debug.Listen,
19 "listen address for go profiling endpoint",
20 )
21 }
22
23 //goland:noinspection GoMixedReceiverTypes
24 func (c *Config) flagSetLog(flagSet *flag.FlagSet) {
25 flagSet.BoolVar(
26 &c.Log.VPNClientIP,
27 "log.vpn-client-ip",
28 c.Log.VPNClientIP,
29 "log IP of VPN client. Useful to have an identifier between OpenVPN and openvpn-auth-oauth2.",
30 )
31 flagSet.StringVar(
32 &c.Log.Format,
33 "log.format",
34 c.Log.Format,
35 "log format. json or console",
36 )
37 flagSet.TextVar(
38 &c.Log.Level,
39 "log.level",
40 c.Log.Level,
41 "log level. Can be one of: debug, info, warn, error",
42 )
43 }
44
45 //goland:noinspection GoMixedReceiverTypes
46 func (c *Config) flagSetHTTP(flagSet *flag.FlagSet) {
47 flagSet.StringVar(
48 &c.HTTP.Listen,
49 "http.listen",
50 c.HTTP.Listen,
51 "listen addr for client listener",
52 )
53 flagSet.BoolVar(
54 &c.HTTP.TLS,
55 "http.tls",
56 c.HTTP.TLS,
57 "enable TLS listener",
58 )
59 flagSet.TextVar(
60 &c.HTTP.BaseURL,
61 "http.baseurl",
62 c.HTTP.BaseURL,
63 "listen addr for client listener",
64 )
65 flagSet.Var(
66 newSecretFlagValue(&c.HTTP.Secret),
67 "http.secret",
68 "Random generated secret for cookie encryption. Must be 16, 24 or 32 characters. "+
69 "If argument starts with file:// it reads the secret from a file.",
70 )
71 flagSet.StringVar(
72 &c.HTTP.KeyFile,
73 "http.key",
74 c.HTTP.KeyFile,
75 "Path to tls server key used for TLS listener.",
76 )
77 flagSet.StringVar(
78 &c.HTTP.CertFile,
79 "http.cert",
80 c.HTTP.CertFile,
81 "Path to tls server certificate used for TLS listener.",
82 )
83 flagSet.TextVar(
84 &c.HTTP.Template,
85 "http.template",
86 c.HTTP.Template,
87 "Path to a HTML file which is displayed at the end of the screen. "+
88 "See https://github.com/jkroepke/openvpn-auth-oauth2/wiki/Layout-Customization for more information.",
89 )
90 flagSet.BoolVar(
91 &c.HTTP.Check.IPAddr,
92 "http.check.ipaddr",
93 c.HTTP.Check.IPAddr,
94 "Check if client IP in http and VPN is equal",
95 )
96 flagSet.BoolVar(
97 &c.HTTP.EnableProxyHeaders,
98 "http.enable-proxy-headers",
99 c.HTTP.EnableProxyHeaders,
100 "Use X-Forwarded-For http header for client ips",
101 )
102 flagSet.TextVar(
103 &c.HTTP.TrustedProxies,
104 "http.trusted-proxies",
105 c.HTTP.TrustedProxies,
106 "Trusted reverse proxy CIDRs allowed to set X-Forwarded-For. Multiple values can be provided as a comma-separated list.",
107 )
108 flagSet.TextVar(
109 &c.HTTP.AssetPath,
110 "http.assets-path",
111 c.HTTP.AssetPath,
112 "Custom path to the assets directory. Files in this directory will be served under /assets/ and having an higher priority than the embedded assets.",
113 )
114 }
115
116 //goland:noinspection GoMixedReceiverTypes
117 func (c *Config) flagSetOpenVPN(flagSet *flag.FlagSet) {
118 flagSet.TextVar(
119 &c.OpenVPN.Addr,
120 "openvpn.addr",
121 c.OpenVPN.Addr,
122 "openvpn management interface addr. Must start with unix:// or tcp://",
123 )
124 flagSet.Var(
125 newSecretFlagValue(&c.OpenVPN.Password),
126 "openvpn.password",
127 "openvpn management interface password. If argument starts with file:// it reads the secret from a file.",
128 )
129 flagSet.BoolVar(
130 &c.OpenVPN.AuthTokenUser,
131 "openvpn.auth-token-user",
132 c.OpenVPN.AuthTokenUser,
133 "Override the username of a session with the username from the token by using auth-token-user, if the client username is empty",
134 )
135 flagSet.DurationVar(
136 &c.OpenVPN.AuthPendingTimeout,
137 "openvpn.auth-pending-timeout",
138 c.OpenVPN.AuthPendingTimeout,
139 "How long OpenVPN server wait until user is authenticated",
140 )
141 flagSet.DurationVar(
142 &c.OpenVPN.CommandTimeout,
143 "openvpn.command-timeout",
144 c.OpenVPN.CommandTimeout,
145 "Maximum time to wait for a response to an OpenVPN management command.",
146 )
147 flagSet.TextVar(
148 &c.OpenVPN.Bypass.CommonNames,
149 "openvpn.bypass.common-names",
150 c.OpenVPN.Bypass.CommonNames,
151 "Skip OAuth authentication for client certificate common names (CNs) matching any of the given regular expressions. "+
152 "Multiple expressions can be provided as a comma-separated list. "+
153 "Regular expressions are automatically anchored (^…$) by default, so \"client\" matches only \"client\". "+
154 "To allow partial matches, specify explicitly (e.g. \"client.*\").",
155 )
156 flagSet.BoolVar(
157 &c.OpenVPN.ClientConfig.Enabled,
158 "openvpn.client-config.enabled",
159 c.OpenVPN.ClientConfig.Enabled,
160 "If true, openvpn-auth-oauth2 will read the CCD directory for additional configuration. This function mimic the client-config-dir directive in OpenVPN.",
161 )
162 flagSet.TextVar(
163 &c.OpenVPN.ClientConfig.Path,
164 "openvpn.client-config.path",
165 c.OpenVPN.ClientConfig.Path,
166 "Path to the CCD directory. openvpn-auth-oauth2 will look for an file with an .conf suffix and returns the content back.",
167 )
168 flagSet.BoolVar(
169 &c.OpenVPN.ClientConfig.IgnoreNotFound,
170 "openvpn.client-config.ignore-not-found",
171 c.OpenVPN.ClientConfig.IgnoreNotFound,
172 "Ignore missing client configuration files.",
173 )
174 flagSet.TextVar(
175 &c.OpenVPN.ClientConfig.Strategy,
176 "openvpn.client-config.strategy",
177 c.OpenVPN.ClientConfig.Strategy,
178 "Client config selection strategy. Values: [merge,user-selector].",
179 )
180 flagSet.StringVar(
181 &c.OpenVPN.ClientConfig.Expression,
182 "openvpn.client-config.expression",
183 c.OpenVPN.ClientConfig.Expression,
184 "CEL expression that returns an ordered list of client configuration names.",
185 )
186 flagSet.StringVar(
187 &c.OpenVPN.CommonName.EnvironmentVariableName,
188 "openvpn.common-name.environment-variable-name",
189 c.OpenVPN.CommonName.EnvironmentVariableName,
190 "Name of the environment variable in the OpenVPN management interface which contains the common name. "+
191 "If username-as-common-name is enabled, this should be set to 'username' to use the username as common name. "+
192 "Other values like 'X509_0_emailAddress' are supported. "+
193 "See https://openvpn.net/community-resources/reference-manual-for-openvpn-2-6/#environmental-variables for more information.",
194 )
195 flagSet.BoolVar(
196 &c.OpenVPN.OverrideUsername,
197 "openvpn.override-username",
198 c.OpenVPN.OverrideUsername,
199 "Requires OpenVPN Server 2.7! "+
200 "If true, openvpn-auth-oauth2 use the override-username command to set the username in OpenVPN connection. "+
201 "This is useful to use real usernames in OpenVPN statistics. The username will be set after client configs are read. "+
202 "Read OpenVPN man page for limitations of the override-username.",
203 )
204 flagSet.BoolVar(
205 &c.OpenVPN.EnforceUniqueUser,
206 "openvpn.enforce-unique-user",
207 c.OpenVPN.EnforceUniqueUser,
208 "Enforces one active OpenVPN session for the username resolved by oauth2.openvpn-username. "+
209 "Requires a direct OpenVPN management-interface connection; the OpenVPN plugin is not supported.",
210 )
211 flagSet.BoolVar(
212 &c.OpenVPN.Passthrough.Enabled,
213 "openvpn.pass-through.enabled",
214 c.OpenVPN.Passthrough.Enabled,
215 "If true, openvpn-auth-oauth2 will setup a pass-through socket for the OpenVPN management interface.",
216 )
217 flagSet.TextVar(
218 &c.OpenVPN.Passthrough.Address,
219 "openvpn.pass-through.address",
220 c.OpenVPN.Passthrough.Address,
221 "The address of the pass-through socket. Must start with unix:// or tcp://",
222 )
223 flagSet.Var(
224 newSecretFlagValue(&c.OpenVPN.Passthrough.Password),
225 "openvpn.pass-through.password",
226 "The password for the pass-through socket. If argument starts with file:// it reads the secret from a file.",
227 )
228 flagSet.StringVar(
229 &c.OpenVPN.Passthrough.SocketGroup,
230 "openvpn.pass-through.socket-group",
231 c.OpenVPN.Passthrough.SocketGroup,
232 "The group for the pass-through socket. Used only, if openvpn.pass-through.address starts with unix:// "+
233 "If empty, the group of the process is used.",
234 )
235 flagSet.TextVar(
236 &c.OpenVPN.Passthrough.SocketMode,
237 "openvpn.pass-through.socket-mode",
238 c.OpenVPN.Passthrough.SocketMode,
239 "The explicit four-digit octal unix file permission mode for the pass-through socket. "+
240 "Used only, if openvpn.pass-through.address starts with unix://",
241 )
242 flagSet.BoolVar(
243 &c.OpenVPN.ReAuthentication,
244 "openvpn.reauthentication",
245 c.OpenVPN.ReAuthentication,
246 "If set to false, openvpn-auth-oauth2 rejects all re-authentication requests.",
247 )
248 }
249
250 //goland:noinspection GoMixedReceiverTypes
251 func (c *Config) flagSetOAuth2(flagSet *flag.FlagSet) {
252 flagSet.TextVar(
253 &c.OAuth2.Issuer,
254 "oauth2.issuer",
255 c.OAuth2.Issuer,
256 "oauth2 issuer",
257 )
258 flagSet.StringVar(
259 &c.OAuth2.Provider,
260 "oauth2.provider",
261 c.OAuth2.Provider,
262 "oauth2 provider",
263 )
264 flagSet.StringVar(
265 &c.OAuth2.AuthorizeParams,
266 "oauth2.authorize-params",
267 c.OAuth2.AuthorizeParams,
268 "additional url query parameter to authorize endpoint",
269 )
270 flagSet.TextVar(
271 &c.OAuth2.Endpoints.Discovery,
272 "oauth2.endpoint.discovery",
273 c.OAuth2.Endpoints.Discovery,
274 "The flag is used to set a custom OAuth2 discovery URL. This URL retrieves the provider's configuration details.",
275 )
276 flagSet.TextVar(
277 &c.OAuth2.Endpoints.Auth,
278 "oauth2.endpoint.auth",
279 c.OAuth2.Endpoints.Auth,
280 "The flag is used to specify a custom OAuth2 authorization endpoint.",
281 )
282 flagSet.TextVar(
283 &c.OAuth2.Endpoints.Token,
284 "oauth2.endpoint.token",
285 c.OAuth2.Endpoints.Token,
286 "The flag is used to specify a custom OAuth2 token endpoint.",
287 )
288 flagSet.StringVar(
289 &c.OAuth2.Client.ID,
290 "oauth2.client.id",
291 c.OAuth2.Client.ID,
292 "oauth2 client id",
293 )
294 flagSet.Var(
295 newSecretFlagValue(&c.OAuth2.Client.PrivateKey),
296 "oauth2.client.private-key",
297 "oauth2 client private key. Secure alternative to oauth2.client.secret. If argument starts with file:// it reads the secret from a file.",
298 )
299 flagSet.StringVar(
300 &c.OAuth2.Client.PrivateKeyID,
301 "oauth2.client.private-key-id",
302 c.OAuth2.Client.PrivateKeyID,
303 "oauth2 client private key id. If specified, JWT assertions will be generated with the specific kid header.",
304 )
305 flagSet.Var(
306 newSecretFlagValue(&c.OAuth2.Client.Secret),
307 "oauth2.client.secret",
308 "oauth2 client secret. If argument starts with file:// it reads the secret from a file.",
309 )
310 flagSet.BoolVar(
311 &c.OAuth2.PKCE,
312 "oauth2.pkce",
313 c.OAuth2.PKCE,
314 "If true, Proof Key for Code Exchange (PKCE) RFC 7636 is used for token exchange.",
315 )
316 flagSet.BoolVar(
317 &c.OAuth2.UserInfo,
318 "oauth2.user-info",
319 c.OAuth2.UserInfo,
320 "If true, openvpn-auth-oauth2 uses the OIDC UserInfo endpoint to fetch additional information about the user (e.g. groups).",
321 )
322 flagSet.StringVar(
323 &c.OAuth2.GroupsClaim,
324 "oauth2.groups-claim",
325 c.OAuth2.GroupsClaim,
326 "Defines the claim name in the ID Token which contains the user groups.",
327 )
328 flagSet.BoolVar(
329 &c.OAuth2.Nonce,
330 "oauth2.nonce",
331 c.OAuth2.Nonce,
332 "If true, a nonce will be defined on the auth URL which is expected inside the token.",
333 )
334 flagSet.TextVar(
335 &c.OAuth2.RefreshNonce,
336 "oauth2.refresh-nonce",
337 c.OAuth2.RefreshNonce,
338 "Controls nonce behavior on refresh token requests. "+
339 "Options: auto (try with nonce, retry without on error), "+
340 "empty (always use empty nonce), "+
341 "equal (use same nonce as initial auth).",
342 )
343 flagSet.TextVar(
344 &c.OAuth2.AuthStyle,
345 "oauth2.auth-style",
346 c.OAuth2.AuthStyle,
347 "Auth style represents how requests for tokens are authenticated to the server. "+
348 "Possible values: auto, params, header. "+
349 "See https://pkg.go.dev/golang.org/x/oauth2#AuthStyle",
350 )
351 flagSet.BoolVar(
352 &c.OAuth2.Refresh.Enabled,
353 "oauth2.refresh.enabled",
354 c.OAuth2.Refresh.Enabled,
355 "If true, openvpn-auth-oauth2 stores refresh tokens and will use it do an non-interaction reauth.",
356 )
357 flagSet.DurationVar(
358 &c.OAuth2.Refresh.Expires,
359 "oauth2.refresh.expires",
360 c.OAuth2.Refresh.Expires,
361 "TTL of stored oauth2 token.",
362 )
363 flagSet.Var(
364 newSecretFlagValue(&c.OAuth2.Refresh.Secret),
365 "oauth2.refresh.secret",
366 "Required, if oauth2.refresh.enabled=true. Random generated secret for token encryption. "+
367 "Must be 16, 24 or 32 characters. If argument starts with file:// it reads the secret from a file.",
368 )
369 flagSet.BoolVar(
370 &c.OAuth2.Refresh.UseSessionID,
371 "oauth2.refresh.use-session-id",
372 c.OAuth2.Refresh.UseSessionID,
373 "If true, openvpn-auth-oauth2 will use the session_id to refresh sessions on initial auth. "+
374 "Requires 'auth-token-gen [lifetime] external-auth' on OpenVPN server.",
375 )
376 flagSet.BoolVar(
377 &c.OAuth2.Refresh.ValidateUser,
378 "oauth2.refresh.validate-user",
379 c.OAuth2.Refresh.ValidateUser,
380 "If true, openvpn-auth-oauth2 will validate the user against the OIDC provider on each refresh. "+
381 "Usefully, if API limits are exceeded or OIDC provider can't deliver an refresh token.",
382 )
383 flagSet.TextVar(
384 &c.OAuth2.Validate.Groups,
385 "oauth2.validate.groups",
386 c.OAuth2.Validate.Groups,
387 "oauth2 required user groups. If multiple groups are configured, the user needs to be least in one group. "+
388 "Comma separated list. Example: group1,group2,group3",
389 )
390 flagSet.StringVar(
391 &c.OAuth2.Validate.Expression,
392 "oauth2.validate.expression",
393 c.OAuth2.Validate.Expression,
394 "CEL expression for custom identity validation. "+
395 "The expression must evaluate to a boolean value. "+
396 "Example: openvpn.commonName == user.username",
397 )
398 flagSet.TextVar(
399 &c.OAuth2.Scopes,
400 "oauth2.scopes",
401 c.OAuth2.Scopes,
402 "oauth2 token scopes. Defaults depends on oauth2.provider. Comma separated list. "+
403 "Example: openid,profile,email",
404 )
405
406 flagSet.StringVar(
407 &c.OAuth2.OpenVPNUsername,
408 "oauth2.openvpn-username",
409 c.OAuth2.OpenVPNUsername,
410 "CEL expression to resolve the username from the normalized identity. The expression must evaluate to a string value. "+
411 "Example: string(token.claims.sub). If empty, the common name is used.",
412 )
413 }
414
415 func (c *Config) flagSetProvider(flagSet *flag.FlagSet) {
416 flagSet.BoolVar(
417 &c.Provider.Google.Validate.GroupsTransitive,
418 "provider.google.validate.groups-transitive",
419 c.Provider.Google.Validate.GroupsTransitive,
420 "If true, required group membership for the Google provider is matched transitively: "+
421 "nested sub-groups of a configured group in oauth2.validate.groups are accepted. "+
422 "Requires the cloud-identity.groups.readonly scope and a Google Workspace/Cloud Identity plan "+
423 "that supports the Cloud Identity checkTransitiveMembership API.",
424 )
425 }