# SAML Identity Provider Reference

This page provides details on the SAML identity provider available in Teleport.

## What is the SAML identity provider?

The SAML identity provider allows Teleport users to authenticate and authorize to external applications, both inside and outside of Teleport, that support SAML Single Sign-On.

## Basic definitions

The following definitions are paraphrased and summarized from OASIS's SAML specification documents, referenced at the bottom of this page.

### Assertions

A package of information that supplies zero or more statements made by an identity provider. Assertions are usually made about a subject, which in Teleport's case will be Teleport users. These can be viewed as statements of fact about a user, e.g. "user *bob* belongs to roles *editor*, *access*."

### Service Provider

A service provider can make use of assertions about a subject in order to control access and provide customized service. They rely on the **identity provider** for these assertions. In Teleport's case, service providers are typically applications like Slack, Vercel, etc. that allow SAML Single Sign-On.

### Identity Provider

A service that makes assertions about a subject.

### Service/identity provider initiated SSO

The login process can be initiated by either the service provider or the identity provider. The processes to trigger either of these are subtly different. The service provider is responsible for initiating the SSO process for service provider initiated SSO. The identity provider is responsible for initiating the process for identity provider initiated SSO.

## Endpoints

### Metadata URL

`https://<proxy-address>/enterprise/saml-idp/metadata`

This is the URL where the identity provider XML metadata can be retrieved from. Service providers will require information from this file to establish the trust between the service provider and identity provider.

### Single Sign-On Service URL

`https://<proxy-address>/enterprise/saml-idp/sso`

This is the URL that service providers will use to exchange assertions with the identity provider. This URL supports the following bindings:

- `HTTP-Redirect`
- `HTTP-POST`

### Identity provider initiated SSO URL

`https://<proxy-address>/enterprise/saml-idp/login/<sp-name>`

This URL triggers identity provider initiated SSO. `sp-name` matches the `metadata.name` of the service provider object for a particular service provider.

## Teleport SAML service provider object

Below is a service provider object. These objects must be added to Teleport in order for Teleport to trust external service providers.

```
kind: saml_idp_service_provider
metadata:
  # The friendly name of the service provider. This is used to manage the
  # service provider as well as in identity provider initiated SSO.
  name: saml-service-provider
spec:
  # The entity_descriptor is the service provider XML.
  entity_descriptor: |
    <md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata"...
version: v1

```

## Assertions

The assertions currently provided by Teleport's SAML identity provider are listed below.

| Friendly name          | Full name                           | Description               | Format                                            |
| ---------------------- | ----------------------------------- | ------------------------- | ------------------------------------------------- |
| `uid`                  | `urn:oid:0.9.2342.19200300.100.1.1` | The user ID from Teleport | `urn:oasis:names:tc:SAML:2.0:attrname-format:uri` |
| `eduPersonAffiliation` | `urn:oid:1.3.6.1.4.1.5923.1.1.1.1`  | The user's Teleport roles | `urn:oasis:names:tc:SAML:2.0:attrname-format:uri` |

## RBAC

Access to the SAML IdP service provider can be configured by using a Teleport role with an allow/deny rule targeting the `saml_idp_service_provider` resource and label matchers matching role `app_labels` with the `saml_idp_service_provider` resource labels.

See this [RBAC guide](https://goteleport.com/docs/identity-governance/idps/saml-idp-rbac.md) to learn more on how to manage access to the SAML IdP Service provider resource in Teleport.

## Troubleshooting

### `Bad Request` when logging into an external application

If the Teleport server returns a `Bad Request` the service provider metadata may not have been added properly to Teleport and, as a result, Teleport is unable to find the service provider. You can verify this by looking for a log entry in Teleport's logs:

```
2023-03-01T10:32:34-05:00 INFO [SAMLIDP]   failed to validate request: cannot find service provider https://samltest.id/saml/sp: could not find service provider https://samltest.id/saml/sp pid:31036.1 saml@v0.4.12/identity_provider.go:232
```

## References

- [Assertions and Protocols for the OASIS SAML 2.0](https://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf)
- [SAML v2.0 Technical Overview](http://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0-cd-02.pdf)
