Skip to content

Commit c9d1d83

Browse files
strehleCopilot
andauthored
Enhance -k skip option to skip issuer check in begin (#120)
* Enhance -k skip option to skip issuer check in begin At start there is a lookup in well-known if issuer from there is the same as passed to command. In case they are not equal the run stops. With -k now this check is ignored and processing is continued. * Update openid-client/openid-client.go Co-authored-by: Copilot <[email protected]> * Update README.md Co-authored-by: Copilot <[email protected]> --------- Co-authored-by: Copilot <[email protected]>
1 parent a3bbaa0 commit c9d1d83

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,26 @@ Flags:
8383
-resource Token-Exchange custom resource parameter.
8484
-requested_type Token-Exchange requested type.
8585
-provider_name Provider name for token-exchange.
86-
-k Skip TLS server certificate verification.
86+
-k Skip TLS server certificate verification and skip OIDC issuer check from well-known.
8787
-v Verbose. Show more details about calls.
8888
-h Show this help for more details.
8989
```
90+
91+
### How to test in automation without showing secrets
92+
In environments with outlog to logs or others it might be needed to hide the secrets and/or client details.
93+
There are some environment variables, which will be used if set. A variable passed to the command itself always as prio before the
94+
environment, but you can also mix input parameters and environment.
95+
96+
* OPENID_ISSUER The issuer of the OIDC server. Useful if you re-use a command often to omit it from a command.
97+
* OPENID_ID The client_id parameter.
98+
* OPENID_SECRET The client_secret parameter.
99+
* OPENID_FORMAT The format of the access_token. Possible values are jwt or opaque.
100+
101+
Example
102+
```text
103+
openid-client client_credentials
104+
```
105+
or with some information
106+
```text
107+
openid-client client_credentials -client_id xxxxx
108+
```

openid-client/openid-client.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func main() {
8686
" -resource Token-Exchange custom resource parameter.\n" +
8787
" -requested_type Token-Exchange requested type.\n" +
8888
" -provider_name Provider name for token-exchange.\n" +
89-
" -k Skip TLS server certificate verification.\n" +
89+
" -k Skip TLS server certificate verification and skip OIDC issuer check from well-known.\n" +
9090
" -v Verbose. Show more details about calls.\n" +
9191
" -h Show this help for more details.")
9292
}
@@ -130,7 +130,7 @@ func main() {
130130
var requestedType = flag.String("requested_type", "", "Token-Exchange requested type")
131131
var providerName = flag.String("provider_name", "", "Provider name for token-exchange")
132132
var resourceParam = flag.String("resource", "", "Additional resource")
133-
var skipTlsVerification = flag.Bool("k", false, "Skip TLS server certificate verification")
133+
var skipTlsVerification = flag.Bool("k", false, "Skip TLS server certificate verification and issuer.")
134134
var mTLS = false
135135
var privateKeyJwt = ""
136136
var arguments []string
@@ -155,6 +155,7 @@ func main() {
155155
return
156156
case "client_credentials", "password", "token-exchange", "jwt-bearer", "saml-bearer", "idp_token", "":
157157
case "passcode", "introspect":
158+
*clientID = os.Getenv("OPENID_ID")
158159
if *clientID == "" {
159160
*clientID = "T000000" /* default */
160161
}
@@ -199,6 +200,9 @@ func main() {
199200
TokenEndPoint string `json:"token_endpoint"`
200201
IntroSpectEndpoint string `json:"introspection_endpoint,omitempty"`
201202
}
203+
if *skipTlsVerification {
204+
ctx = oidc.InsecureIssuerURLContext(ctx, *issEndPoint)
205+
}
202206
provider, oidcError := oidc.NewProvider(ctx, *issEndPoint)
203207
if oidcError != nil {
204208
if *urlEndPoint != "" && *command != "" {
@@ -354,8 +358,11 @@ func main() {
354358
requestMap.Set("client_assertion", privateKeyJwt)
355359
}
356360
var verbose = *isVerbose
357-
if *tokenFormatParameter != "" && *doCfCall == false {
361+
var envFormat = os.Getenv("OPENID_FORMAT")
362+
if *tokenFormatParameter != "" && envFormat == "" && *doCfCall == false {
358363
requestMap.Set("token_format", *tokenFormatParameter)
364+
} else if envFormat != "" {
365+
requestMap.Set("token_format", envFormat)
359366
}
360367
if *appTid != "" {
361368
requestMap.Set("app_tid", *appTid)

0 commit comments

Comments
 (0)