Skip to content
Merged
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
121 changes: 121 additions & 0 deletions docs/en/solutions/OIDC_field_mapping_configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
products:
- Alauda Container Platform
kind:
- Solution
---

# OIDC Field Mapping Configuration

## Issue

When integrating third-party OIDC (OpenID Connect) services, authentication callback failures are frequently encountered, with the error message typically being:

`Internal error occurred: failed to authenticate: missing email claim, not found \"email\" key`

The platform requests the default scopes `profile` and `email` during OIDC authentication. However, some third-party OIDC providers may not return standard fields in the expected format.

**Common error messages:**

- missing "email" claim: Missing email field
- missing "email_verified" claim: Missing email verification field
- missing "name" claim: Missing name field

## Environment

- 4.x
- 3.x

## Resolution

The platform provides a field mapping feature to handle these non-standard situations.

### For Platform Version 4.x

1. Navigate to Administrator → Users → IDP → Click to enter OIDC integration details → Click Update on the right side of Actions → Switch to YAML view

2. Configure field mapping in the YAML:

```yaml
spec:
config:
# Other configurations
# If the Provider cannot provide the email_verified field, the email verification check can be skipped.
insecureSkipEmailVerified: true

Comment on lines +43 to +45
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add a security warning for insecureSkipEmailVerified

Skipping email verification lowers identity assurance. Call this out prominently.

     insecureSkipEmailVerified: true
+
+**Warning:** Only set `insecureSkipEmailVerified: true` for trusted, internal IdPs where email ownership is validated by policy. Otherwise prefer fixing the IdP claims or using `getUserInfo` to retrieve `email_verified`.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# If the Provider cannot provide the email_verified field, the email verification check can be skipped.
insecureSkipEmailVerified: true
# If the Provider cannot provide the email_verified field, the email verification check can be skipped.
insecureSkipEmailVerified: true
**Warning:** Only set `insecureSkipEmailVerified: true` for trusted, internal IdPs where email ownership is validated by policy. Otherwise prefer fixing the IdP claims or using `getUserInfo` to retrieve `email_verified`.
🤖 Prompt for AI Agents
In docs/en/solutions/OIDC_field_mapping_configuration.md around lines 43 to 45,
add a prominent security warning near the insecureSkipEmailVerified example
explaining that setting insecureSkipEmailVerified: true lowers identity
assurance and should only be used in controlled, non-production or legacy
scenarios; instruct readers to avoid it in production, prefer configuring the
Provider to supply email_verified or implement alternative verification flows,
and include an explicit caution about potential account takeover and compliance
risks.

# Use other fields as the display name; the default is the name field.
userNameKey: display_name

# If the provider's /.well-known/openid-configuration provides a userinfo_endpoint, the UserInfo endpoint query can be enabled.
getUserInfo: true

# Field Mapping Configuration
claimMapping:
# If the provider cannot provide the email field, 'sub' can be used as a substitute.
# In addition to the sub field, other fields that can uniquely represent a user globally may also be used.
# Default email
email: sub

# If the provider uses 'user_groups' instead of 'groups'
# Default groups
groups: user_groups

# If the provider uses 'mobile' instead of 'phone'
phone: mobile
```

3. After updating the field mappings in the IDP configuration, users can attempt to log in again using OIDC.

For detailed documentation related to version 4.x, please refer to: [https://docs.alauda.io/container_platform/4.1/security/users_and_roles/idp/functions/oidc_manage.html](https://docs.alauda.io/container_platform/4.1/security/users_and_roles/idp/functions/oidc_manage.html)

### For Platform Version 3.x

1. Execute the following commands in the global cluster:

```bash
# Retrieve the connected provider(s).
kubectl get connectors -n cpaas-system

# Edit connector information
kubectl edit connector -n cpaas-system <connector name>
```

2. Decode the value of the config field using Base64.

The configuration information of the Provider will be displayed in JSON format. At this point, you can update the configuration in the JSON according to the field configuration of version 4.x. Finally, encode the information in base64 and update it to the connector resource.

Comment on lines +83 to +86
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Provide concrete Base64 decode/encode commands and newline handling

Avoid common pitfalls with trailing newlines and line-wrapping.

-2. Decode the value of the config field using Base64.
-
-The configuration information of the Provider will be displayed in JSON format. At this point, you can update the configuration in the JSON according to the field configuration of version 4.x. Finally, encode the information in base64 and update it to the connector resource.
+2. Decode the `config` field (Base64), edit JSON, then re-encode:
+
+```bash
+# Decode to file
+kubectl get connector -n cpaas-system <connector-name> -o json \
+  | jq -r '.spec.config' | base64 -d > oidc-config.json
+
+# Edit JSON per 4.x field mappings
+$EDITOR oidc-config.json
+
+# Re-encode without line wraps and patch back
+ENCODED=$(base64 -w0 < oidc-config.json)
+kubectl patch connector -n cpaas-system <connector-name> --type merge -p "{\"spec\":{\"config\":\"$ENCODED\"}}"
+```
🤖 Prompt for AI Agents
In docs/en/solutions/OIDC_field_mapping_configuration.md around lines 83-86, the
instructions are missing concrete Base64 decode/encode commands and newline
handling; update the doc to show exact shell steps: use kubectl to output the
connector JSON, extract the .spec.config with jq -r and base64 -d redirecting to
a file, edit the JSON, then re-encode without line-wrapping (base64 --wrap=0 or
base64 -w0) and patch the connector with kubectl patch using a JSON merge patch
(ensure proper quoting/escaping of the encoded string); also note the macOS
base64 flag difference and recommend verifying no trailing newline is introduced
when re-encoding.

After updating the Connector configuration, you can use OIDC to log in to the platform again.

## Root Cause

The root cause of this type of issue is that the ID Token returned by the third-party OIDC service lacks standard mandatory fields, preventing the system from correctly parsing user information.

ID Tokens contain standard claims that assert which client app logged the user in, when the token expires, and the identity of the user.

**Standard ID Token example:**

```json
{
"iss": "http://127.0.0.1:5556/dex",
"sub": "CgcyMzQyNzQ5EgZnaXRodWI",
"aud": "example-app",
"exp": 1492882042,
"iat": 1492795642,
"at_hash": "bi96gOXZShvlWYtal9Eqiw",
"email": "jane.doe@coreos.com",
"email_verified": true,
"groups": [
"admins",
"developers"
],
"name": "Jane Doe"
}
```

## Diagnostic Steps

1. **Check the ID Token content**: You can use an online JWT decoding tool (such as [https://jwt.io](https://jwt.io)) to view the actual content of the ID Token and understand which fields the OIDC service provides.

2. **Consult the IDP provider**: To map the required fields, consult the IDP provider's operations personnel to determine which fields were provided during authorization.

3. **Verify authentication flow**: Test the OIDC authentication process to identify specific missing claims in the error messages.
Comment on lines +117 to +121
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add caution: don’t paste live tokens into third‑party sites

Recommend local decoding to avoid leaking tokens.

-1. **Check the ID Token content**: You can use an online JWT decoding tool (such as [https://jwt.io](https://jwt.io)) to view the actual content of the ID Token and understand which fields the OIDC service provides.
+1. **Check the ID Token content**: Prefer local decoding to avoid exposing tokens to third parties. Example:
+
+```bash
+# ID token structure (header.payload.signature)
+cut -d. -f2 <<< "$ID_TOKEN" | base64 -d 2>/dev/null | jq .
+```
+If using an online tool (e.g., jwt.io), never paste production tokens.
🤖 Prompt for AI Agents
In docs/en/solutions/OIDC_field_mapping_configuration.md around lines 117–121,
add a clear caution not to paste live/production ID Tokens into third‑party
sites and instead recommend decoding tokens locally; update the section to (1)
prepend a short warning statement discouraging use of online JWT tools with
production tokens, (2) advise performing local decoding using common CLI tools
by extracting the token payload, base64‑decoding it, and pretty‑printing with
jq, and (3) include a fenced code block showing an example local decode command
and a note to redact or use non‑production tokens when using any online decoder.