Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
This folder describes third-party authentications supported by Ansible Tower. These authentications can be configured and enabled inside Tower.
|
||||
|
||||
When a user wants to log into Tower, she can explicitly choose some of the supported authentications to log in instead of Tower's own authentication using username and password. Here is a list of such authentications:
|
||||
* Google OAuth2
|
||||
* Github OAuth2
|
||||
* Github Organization OAuth2
|
||||
* Github Team OAuth2
|
||||
* Github Enterprise OAuth2
|
||||
* Github Enterprise Organization OAuth2
|
||||
* Github Enterprise Team OAuth2
|
||||
* Microsoft Azure Active Directory (AD) OAuth2
|
||||
|
||||
On the other hand, the other authentication methods use the same types of login info as Tower (username and password), but authenticate using external auth systems rather than Tower's own database. If some of these methods are enabled, Tower will try authenticating using the enabled methods *before Tower's own authentication method*. The order of precedence is:
|
||||
* LDAP
|
||||
* RADIUS
|
||||
* TACACS+
|
||||
* SAML
|
||||
|
||||
Tower will try authenticating against each enabled authentication method *in the specified order*, meaning if the same username and password is valid in multiple enabled auth methods (*e.g.*, both LDAP and TACACS+), Tower will only use the first positive match (in the above example, log a user in via LDAP and skip TACACS+).
|
||||
|
||||
## Notes:
|
||||
SAML users, RADIUS users and TACACS+ users are categorized as 'Enterprise' users. The following rules apply to Enterprise users:
|
||||
|
||||
* Enterprise users can only be created via the first successful login attempt from remote authentication backend.
|
||||
* Enterprise users cannot be created/authenticated if non-enterprise users with the same name has already been created in Tower.
|
||||
* Tower passwords of Enterprise users should always be empty and cannot be set by any user if there are enterprise backends enabled.
|
||||
* If enterprise backends are disabled, an Enterprise user can be converted to a normal Tower user by setting password field. But this operation is irreversible (the converted Tower user can no longer be treated as Enterprise user).
|
||||
@@ -0,0 +1,68 @@
|
||||
# LDAP
|
||||
The Lightweight Directory Access Protocol (LDAP) is an open, vendor-neutral, industry-standard application protocol for accessing and maintaining distributed directory information services over an Internet Protocol (IP) network. Directory services play an important role in developing intranet and Internet applications by allowing the sharing of information about users, systems, networks, services, and applications throughout the network.
|
||||
|
||||
|
||||
# Configure LDAP Authentication
|
||||
|
||||
Please see the [Tower documentation](https://docs.ansible.com/ansible-tower/latest/html/administration/ldap_auth.html) as well as [Ansible blog post](https://www.ansible.com/blog/getting-started-ldap-authentication-in-ansible-tower) for basic LDAP configuration.
|
||||
|
||||
LDAP Authentication provides duplicate sets of configuration fields for authentication with up to six different LDAP servers.
|
||||
The default set of configuration fields take the form `AUTH_LDAP_<field name>`. Configuration fields for additional LDAP servers are numbered `AUTH_LDAP_<n>_<field name>`.
|
||||
|
||||
|
||||
## Test Environment Setup
|
||||
|
||||
Please see `README.md` of this repository: https://github.com/ansible/deploy_ldap
|
||||
|
||||
|
||||
# Basic Setup for FreeIPA
|
||||
|
||||
LDAP Server URI (append if you have multiple LDAPs)
|
||||
`ldaps://{{serverip1}}:636`
|
||||
|
||||
LDAP BIND DN (How to create a bind account in [FreeIPA](https://www.freeipa.org/page/Creating_a_binddn_for_Foreman)
|
||||
`uid=awx-bind,cn=sysaccounts,cn=etc,dc=example,dc=com`
|
||||
|
||||
LDAP BIND PASSWORD
|
||||
`{{yourbindaccountpassword}}`
|
||||
|
||||
LDAP USER DN TEMPLATE
|
||||
`uid=%(user)s,cn=users,cn=accounts,dc=example,dc=com`
|
||||
|
||||
LDAP GROUP TYPE
|
||||
`NestedMemberDNGroupType`
|
||||
|
||||
LDAP GROUP SEARCH
|
||||
```
|
||||
[
|
||||
"cn=groups,cn=accounts,dc=example,dc=com",
|
||||
"SCOPE_SUBTREE",
|
||||
"(objectClass=groupOfNames)"
|
||||
]
|
||||
```
|
||||
|
||||
LDAP USER ATTRIBUTE MAP
|
||||
```
|
||||
{
|
||||
"first_name": "givenName",
|
||||
"last_name": "sn",
|
||||
"email": "mail"
|
||||
}
|
||||
```
|
||||
|
||||
LDAP USER FLAGS BY GROUP
|
||||
```
|
||||
{
|
||||
"is_superuser": "cn={{superusergroupname}},cn=groups,cn=accounts,dc=example,dc=com"
|
||||
}
|
||||
```
|
||||
|
||||
LDAP ORGANIZATION MAP
|
||||
```
|
||||
{
|
||||
"{{yourorganizationname}}": {
|
||||
"admins": "cn={{admingroupname}},cn=groups,cn=accounts,dc=example,dc=com",
|
||||
"remove_admins": false
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -0,0 +1,403 @@
|
||||
## Introduction
|
||||
Starting from Tower 3.3, OAuth2 will be used as the new means of token-based authentication. Users
|
||||
will be able to manage OAuth2 tokens as well as applications, a server-side representation of API
|
||||
clients used to generate tokens. With OAuth2, a user can authenticate by passing a token as part of
|
||||
the HTTP authentication header. The token can be scoped to have more restrictive permissions on top of
|
||||
the base RBAC permissions of the user. Refer to [RFC 6749](https://tools.ietf.org/html/rfc6749) for
|
||||
more details of OAuth2 specification.
|
||||
|
||||
## Basic Usage
|
||||
|
||||
To get started using OAuth2 tokens for accessing the browsable API using OAuth2, this document will walk through the steps of acquiring a token and using it.
|
||||
|
||||
1. Make an application with `authorization_grant_type` set to 'password'. HTTP POST the following to the `/api/v2/applications/` endpoint (supplying your own `organization-id`):
|
||||
```
|
||||
{
|
||||
"name": "Admin Internal Application",
|
||||
"description": "For use by secure services & clients. ",
|
||||
"client_type": "confidential",
|
||||
"redirect_uris": "",
|
||||
"authorization_grant_type": "password",
|
||||
"skip_authorization": false,
|
||||
"organization": <organization-id>
|
||||
}
|
||||
```
|
||||
2. Make a token with a POST to the `/api/v2/tokens/` endpoint:
|
||||
```
|
||||
{
|
||||
"description": "My Access Token",
|
||||
"application": <application-id>,
|
||||
"scope": "write"
|
||||
}
|
||||
```
|
||||
This will return a `<token-value>` that you can use to authenticate with for future requests (this will not be shown again)
|
||||
|
||||
3. Use token to access a resource. We will use `curl` to demonstrate this:
|
||||
```
|
||||
curl -H "Authorization: Bearer <token-value>" -X GET https://<awx>/api/v2/users/
|
||||
```
|
||||
> The `-k` flag may be needed if you have not set up a CA yet and are using SSL.
|
||||
|
||||
This token can be revoked by making a DELETE on the detail page for that token. All you need is that token's id. For example:
|
||||
```
|
||||
curl -ku <user>:<password> -X DELETE https://<awx>/api/v2/tokens/<pk>/
|
||||
```
|
||||
|
||||
Similarly, using a token:
|
||||
```
|
||||
curl -H "Authorization: Bearer <token-value>" -X DELETE https://<awx>/api/v2/tokens/<pk>/ -k
|
||||
```
|
||||
|
||||
|
||||
## More Information
|
||||
|
||||
#### Managing OAuth2 Applications and Tokens
|
||||
|
||||
Applications and tokens can be managed as a top-level resource at `/api/v2/applications` and
|
||||
`/api/v2/tokens`. These resources can also be accessed respective to the user at
|
||||
`/api/v2/users/N/<resource>`. Applications can be created by making a POST to either `api/v2/applications`
|
||||
or `/api/v2/users/N/applications`.
|
||||
|
||||
Each OAuth2 application represents a specific API client on the server side. For an API client to use the API via an application token,
|
||||
it must first have an application and issue an access token.
|
||||
|
||||
Individual applications will be accessible via their primary keys:
|
||||
`/api/v2/applications/<pk>/`. Here is a typical application:
|
||||
```
|
||||
{
|
||||
"id": 1,
|
||||
"type": "o_auth2_application",
|
||||
"url": "/api/v2/applications/1/",
|
||||
"related": {
|
||||
"user": "/api/v2/users/1/",
|
||||
"tokens": "/api/v2/applications/1/tokens/",
|
||||
"activity_stream": "/api/v2/applications/1/activity_stream/"
|
||||
},
|
||||
"summary_fields": {
|
||||
"user": {
|
||||
"id": 1,
|
||||
"username": "root",
|
||||
"first_name": "",
|
||||
"last_name": ""
|
||||
},
|
||||
"tokens": {
|
||||
"count": 1,
|
||||
"results": [
|
||||
{
|
||||
"scope": "read",
|
||||
"token": "*************",
|
||||
"id": 2
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"created": "2018-02-20T23:06:43.215315Z",
|
||||
"modified": "2018-02-20T23:06:43.215375Z",
|
||||
"name": "Default application for root",
|
||||
"user": 1,
|
||||
"client_id": "BIyE720WAjr14nNxGXrBbsRsG0FkjgeL8cxNmIWP",
|
||||
"client_secret": "OdO6TMNAYxUVv4HLitLOnRdAvtClEV8l99zlb8EJEZjlzVNaVVlWiKXicznLDeANwu5qRgeQRvD3AnuisQGCPXXRCx79W1ARQ5cSmc9mrU1JbqW7nX3IZYhLIFgsDH8u",
|
||||
"client_type": "confidential",
|
||||
"redirect_uris": "",
|
||||
"authorization_grant_type": "password",
|
||||
"skip_authorization": false
|
||||
},
|
||||
```
|
||||
In the above example, `user` is the primary key of the user associated to this application and `name` is
|
||||
a human-readable identifier for the application. The other fields, like `client_id` and
|
||||
`redirect_uris`, are mainly used for OAuth2 authorization, which will be covered later in the 'Using
|
||||
OAuth2 Token System' section.
|
||||
|
||||
Fields `client_id` and `client_secret` are immutable identifiers of applications, and will be
|
||||
generated during creation; Fields `user` and `authorization_grant_type`, on the other hand, are
|
||||
*immutable on update*, meaning they are required fields on creation, but will become read-only after
|
||||
that.
|
||||
|
||||
**On RBAC side:**
|
||||
- System admins will be able to see and manipulate all applications in the system;
|
||||
- Organization admins will be able to see and manipulate all applications belonging to Organization
|
||||
members;
|
||||
- Other normal users will only be able to see, update and delete their own applications, but
|
||||
cannot create any new applications.
|
||||
|
||||
Tokens, on the other hand, are resources used to actually authenticate incoming requests and mask the
|
||||
permissions of the underlying user. Tokens can be created by POSTing to `/api/v2/tokens/`
|
||||
endpoint by providing `application` and `scope` fields to point to related application and specify
|
||||
token scope; or POSTing to `/api/v2/applications/<pk>/tokens/` by providing only `scope`, while
|
||||
the parent application will be automatically linked.
|
||||
|
||||
Individual tokens will be accessible via their primary keys at
|
||||
`/api/v2/tokens/<pk>/`. Here is a typical token:
|
||||
```
|
||||
{
|
||||
"id": 4,
|
||||
"type": "o_auth2_access_token",
|
||||
"url": "/api/v2/tokens/4/",
|
||||
"related": {
|
||||
"user": "/api/v2/users/1/",
|
||||
"application": "/api/v2/applications/1/",
|
||||
"activity_stream": "/api/v2/tokens/4/activity_stream/"
|
||||
},
|
||||
"summary_fields": {
|
||||
"application": {
|
||||
"id": 1,
|
||||
"name": "Default application for root",
|
||||
"client_id": "mcU5J5uGQcEQMgAZyr5JUnM3BqBJpgbgL9fLOVch"
|
||||
},
|
||||
"user": {
|
||||
"id": 1,
|
||||
"username": "root",
|
||||
"first_name": "",
|
||||
"last_name": ""
|
||||
}
|
||||
},
|
||||
"created": "2018-02-23T14:39:32.618932Z",
|
||||
"modified": "2018-02-23T14:39:32.643626Z",
|
||||
"description": "App Token Test",
|
||||
"user": 1,
|
||||
"token": "*************",
|
||||
"refresh_token": "*************",
|
||||
"application": 1,
|
||||
"expires": "2018-02-24T00:39:32.618279Z",
|
||||
"scope": "read"
|
||||
},
|
||||
```
|
||||
For an OAuth2 token, the only fully mutable fields are `scope` and `description`. The `application`
|
||||
field is *immutable on update*, and all other fields are totally immutable, and will be auto-populated
|
||||
during creation.
|
||||
* `user` - this field corresponds to the user the token is created for
|
||||
* `expires` will be generated according to Tower configuration setting `OAUTH2_PROVIDER`
|
||||
* `token` and `refresh_token` will be auto-generated to be non-clashing random strings.
|
||||
|
||||
Both application tokens and personal access tokens will be shown at the `/api/v2/tokens/`
|
||||
endpoint. Personal access tokens can be identified by the `application` field being `null`.
|
||||
|
||||
**On RBAC side:**
|
||||
- A user will be able to create a token if they are able to see the related application;
|
||||
- The System Administrator is able to see and manipulate every token in the system;
|
||||
- Organization admins will be able to see and manipulate all tokens belonging to Organization
|
||||
members;
|
||||
System Auditors can see all tokens and applications
|
||||
- Other normal users will only be able to see and manipulate their own tokens.
|
||||
> Note: Users can only see the token or refresh-token _value_ at the time of creation ONLY.
|
||||
|
||||
#### Using OAuth2 Token System for Personal Access Tokens (PAT)
|
||||
The most common usage of OAuth2 is authenticating users. The `token` field of a token is used
|
||||
as part of the HTTP authentication header, in the format `Authorization: Bearer <token field value>`. This _Bearer_
|
||||
token can be obtained by doing a curl to the `/api/o/token/` endpoint. For example:
|
||||
```
|
||||
curl -ku <user>:<password> -H "Content-Type: application/json" -X POST \
|
||||
-d '{"description":"Tower CLI", "application":null, "scope":"write"}' \
|
||||
https://<awx>/api/v2/users/1/personal_tokens/ | python -m json.tool
|
||||
```
|
||||
Here is an example of using that PAT to access an API endpoint using `curl`:
|
||||
```
|
||||
curl -H "Authorization: Bearer kqHqxfpHGRRBXLNCOXxT5Zt3tpJogn" http://<awx>/api/v2/credentials/
|
||||
```
|
||||
|
||||
According to OAuth2 specification, users should be able to acquire, revoke and refresh an access
|
||||
token. In AWX the equivalent, and easiest, way of doing that is creating a token, deleting
|
||||
a token, and deleting a token quickly followed by creating a new one.
|
||||
|
||||
The specification also provides standard ways of doing this. RFC 6749 elaborates
|
||||
on those topics, but in summary, an OAuth2 token is officially acquired via authorization using
|
||||
authorization information provided by applications (special application fields mentioned above).
|
||||
There are dedicated endpoints for authorization and acquiring tokens. The `token` endpoint
|
||||
is also responsible for token refresh, and token revoke can be done by the dedicated token revoke endpoint.
|
||||
|
||||
In AWX, our OAuth2 system is built on top of
|
||||
[Django Oauth Toolkit](https://django-oauth-toolkit.readthedocs.io/en/latest/), which provides full
|
||||
support on standard authorization, token revoke and refresh. AWX implements them and puts related
|
||||
endpoints under `/api/o/` endpoint. Detailed examples on the most typical usage of those endpoints
|
||||
are available as description text of `/api/o/`. See below for information on Application Access Token usage.
|
||||
> Note: The `/api/o/` endpoints can only be used for application tokens, and are not valid for personal access tokens.
|
||||
|
||||
|
||||
#### Token Scope Mask Over RBAC System
|
||||
|
||||
The scope of an OAuth2 token is a space-separated string composed of keywords like 'read' and 'write'.
|
||||
These keywords are configurable and used to specify permission level of the authenticated API client.
|
||||
For the initial OAuth2 implementation, we use the most simple scope configuration, where the only
|
||||
valid scope keywords are 'read' and 'write'.
|
||||
|
||||
Read and write scopes provide a mask layer over the RBAC permission system of AWX. In specific, a
|
||||
'write' scope gives the authenticated user the full permissions the RBAC system provides, while 'read'
|
||||
scope gives the authenticated user only read permissions the RBAC system provides.
|
||||
|
||||
For example, if a user has admin permission to a job template, he/she can both see and modify, launch
|
||||
and delete the job template if authenticated via session or basic auth. On the other hand, if the user
|
||||
is authenticated using OAuth2 token, and the related token scope is 'read', the user can only see but
|
||||
not manipulate or launch the job template, despite being an admin. If the token scope is
|
||||
'write' or 'read write', she can take full advantage of the job template as its admin. Note that 'write'
|
||||
implies 'read' as well.
|
||||
|
||||
|
||||
## Application Functions
|
||||
|
||||
This page lists OAuth2 utility endpoints used for authorization, token refresh and revoke.
|
||||
Note endpoints other than `/api/o/authorize/` are not meant to be used in browsers and do not
|
||||
support HTTP GET. The endpoints here strictly follow
|
||||
[RFC specs for OAuth2](https://tools.ietf.org/html/rfc6749), so please use that for detailed
|
||||
reference. Below are some examples to demonstrate the typical usage of these endpoints in
|
||||
AWX context (note that the AWX net location defaults to `http://localhost:8013` in these examples).
|
||||
|
||||
|
||||
#### Application Using `authorization code` Grant Type
|
||||
|
||||
This application grant type is intended to be used when the application is executing on the server. To create
|
||||
an application named `AuthCodeApp` with the `authorization-code` grant type,
|
||||
make a POST to the `/api/v2/applications/` endpoint:
|
||||
```text
|
||||
{
|
||||
"name": "AuthCodeApp",
|
||||
"user": 1,
|
||||
"client_type": "confidential",
|
||||
"redirect_uris": "http://<awx>/api/v2",
|
||||
"authorization_grant_type": "authorization-code",
|
||||
"skip_authorization": false
|
||||
}
|
||||
```
|
||||
You can test the authorization flow out with this new application by copying the `client_id` and URI link into the
|
||||
homepage [here](http://django-oauth-toolkit.herokuapp.com/consumer/) and click submit. This is just a simple test
|
||||
application `Django-oauth-toolkit` provides.
|
||||
|
||||
From the client app, the user makes a GET to the Authorize endpoint with the `response_type`,
|
||||
`client_id`, `redirect_uris`, and `scope`. AWX will respond with the authorization `code` and `state`
|
||||
to the `redirect_uri` specified in the application. The client application will then make a POST to the
|
||||
`api/o/token/` endpoint on AWX with the `code`, `client_id`, `client_secret`, `grant_type`, and `redirect_uri`.
|
||||
AWX will respond with the `access_token`, `token_type`, `refresh_token`, and `expires_in`. For more
|
||||
information on testing this flow, refer to [django-oauth-toolkit](http://django-oauth-toolkit.readthedocs.io/en/latest/tutorial/tutorial_01.html#test-your-authorization-server).
|
||||
|
||||
|
||||
#### Application Using `password` Grant Type
|
||||
|
||||
This is also called the `resource owner credentials grant`. This is for use by users who have
|
||||
native access to the web app. This should be used when the client is the Resource owner. Suppose
|
||||
we have an application `Default Application` with grant type `password`:
|
||||
```text
|
||||
{
|
||||
"id": 6,
|
||||
"type": "application",
|
||||
...
|
||||
"name": "Default Application",
|
||||
"user": 1,
|
||||
"client_id": "gwSPoasWSdNkMDtBN3Hu2WYQpPWCO9SwUEsKK22l",
|
||||
"client_secret": "fI6ZpfocHYBGfm1tP92r0yIgCyfRdDQt0Tos9L8a4fNsJjQQMwp9569eIaUBsaVDgt2eiwOGe0bg5m5vCSstClZmtdy359RVx2rQK5YlIWyPlrolpt2LEpVeKXWaiybo",
|
||||
"client_type": "confidential",
|
||||
"redirect_uris": "",
|
||||
"authorization_grant_type": "password",
|
||||
"skip_authorization": false
|
||||
}
|
||||
```
|
||||
|
||||
Login is not required for `password` grant type, so we can simply use `curl` to acquire a personal access token
|
||||
via `/api/o/token/`:
|
||||
```bash
|
||||
curl -X POST \
|
||||
-d "grant_type=password&username=<username>&password=<password>&scope=read" \
|
||||
-u "gwSPoasWSdNkMDtBN3Hu2WYQpPWCO9SwUEsKK22l:fI6ZpfocHYBGfm1tP92r0yIgCyfRdDQt0Tos9L8a4fNsJjQQMwp9569e
|
||||
IaUBsaVDgt2eiwOGe0bg5m5vCSstClZmtdy359RVx2rQK5YlIWyPlrolpt2LEpVeKXWaiybo" \
|
||||
http://<awx>/api/o/token/ -i
|
||||
```
|
||||
In the above POST request, parameters `username` and `password` are the username and password of the related
|
||||
AWX user of the underlying application, and the authentication information is of format
|
||||
`<client_id>:<client_secret>`, where `client_id` and `client_secret` are the corresponding fields of
|
||||
underlying application.
|
||||
|
||||
Upon success, the access token, refresh token and other information are given in the response body in JSON
|
||||
format:
|
||||
```text
|
||||
HTTP/1.1 200 OK
|
||||
Server: nginx/1.12.2
|
||||
Date: Tue, 05 Dec 2017 16:48:09 GMT
|
||||
Content-Type: application/json
|
||||
Content-Length: 163
|
||||
Connection: keep-alive
|
||||
Content-Language: en
|
||||
Vary: Accept-Language, Cookie
|
||||
Pragma: no-cache
|
||||
Cache-Control: no-store
|
||||
Strict-Transport-Security: max-age=15768000
|
||||
|
||||
{"access_token": "9epHOqHhnXUcgYK8QanOmUQPSgX92g", "token_type": "Bearer", "expires_in": 315360000000, "refresh_token": "jMRX6QvzOTf046KHee3TU5mT3nyXsz", "scope": "read"}
|
||||
```
|
||||
|
||||
|
||||
## Token Functions
|
||||
|
||||
#### Refresh an Existing Access Token
|
||||
|
||||
Suppose we have an existing access token with refresh token provided:
|
||||
```text
|
||||
{
|
||||
"id": 35,
|
||||
"type": "access_token",
|
||||
...
|
||||
"user": 1,
|
||||
"token": "omMFLk7UKpB36WN2Qma9H3gbwEBSOc",
|
||||
"refresh_token": "AL0NK9TTpv0qp54dGbC4VUZtsZ9r8z",
|
||||
"application": 6,
|
||||
"expires": "2017-12-06T03:46:17.087022Z",
|
||||
"scope": "read write"
|
||||
}
|
||||
```
|
||||
The `/api/o/token/` endpoint is used for refreshing the access token:
|
||||
```bash
|
||||
curl -X POST \
|
||||
-d "grant_type=refresh_token&refresh_token=AL0NK9TTpv0qp54dGbC4VUZtsZ9r8z" \
|
||||
-u "gwSPoasWSdNkMDtBN3Hu2WYQpPWCO9SwUEsKK22l:fI6ZpfocHYBGfm1tP92r0yIgCyfRdDQt0Tos9L8a4fNsJjQQMwp9569eIaUBsaVDgt2eiwOGe0bg5m5vCSstClZmtdy359RVx2rQK5YlIWyPlrolpt2LEpVeKXWaiybo" \
|
||||
http://<awx>/api/o/token/ -i
|
||||
```
|
||||
In the above POST request, `refresh_token` is provided by `refresh_token` field of the access token
|
||||
above. The authentication information is of format `<client_id>:<client_secret>`, where `client_id`
|
||||
and `client_secret` are the corresponding fields of underlying related application of the access token.
|
||||
|
||||
Upon success, the new (refreshed) access token with the same scope information as the previous one is
|
||||
given in the response body in JSON format:
|
||||
```text
|
||||
HTTP/1.1 200 OK
|
||||
Server: nginx/1.12.2
|
||||
Date: Tue, 05 Dec 2017 17:54:06 GMT
|
||||
Content-Type: application/json
|
||||
Content-Length: 169
|
||||
Connection: keep-alive
|
||||
Content-Language: en
|
||||
Vary: Accept-Language, Cookie
|
||||
Pragma: no-cache
|
||||
Cache-Control: no-store
|
||||
Strict-Transport-Security: max-age=15768000
|
||||
|
||||
{"access_token": "NDInWxGJI4iZgqpsreujjbvzCfJqgR", "token_type": "Bearer", "expires_in": 315360000000, "refresh_token": "DqOrmz8bx3srlHkZNKmDpqA86bnQkT", "scope": "read write"}
|
||||
```
|
||||
Internally, the refresh operation deletes the existing token and a new token is created immediately
|
||||
after, with information like scope and related application identical to the original one. We can
|
||||
verify by checking the new token is present and the old token is deleted at the `/api/v2/tokens/` endpoint.
|
||||
|
||||
|
||||
#### Revoke an Access Token
|
||||
|
||||
##### Alternatively Revoke Using the /api/o/revoke-token/ Endpoint
|
||||
|
||||
Revoking an access token by this method is the same as deleting the token resource object, but it allows you to delete a token by providing its token value, and the associated `client_id` (and `client_secret` if the application is `confidential`). For example:
|
||||
```bash
|
||||
curl -X POST -d "token=rQONsve372fQwuc2pn76k3IHDCYpi7" \
|
||||
-u "gwSPoasWSdNkMDtBN3Hu2WYQpPWCO9SwUEsKK22l:fI6ZpfocHYBGfm1tP92r0yIgCyfRdDQt0Tos9L8a4fNsJjQQMwp9569eIaUBsaVDgt2eiwOGe0bg5m5vCSstClZmtdy359RVx2rQK5YlIWyPlrolpt2LEpVeKXWaiybo" \
|
||||
http://<awx>/api/o/revoke_token/ -i
|
||||
```
|
||||
`200 OK` means a successful delete.
|
||||
|
||||
We can verify the effect by checking if the token is no longer present
|
||||
at `/api/v2/tokens/`.
|
||||
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
* All CRUD operations for OAuth2 applications and tokens should function as described.
|
||||
* RBAC rules applied to OAuth2 applications and tokens should behave as described.
|
||||
* A default application should be auto-created for each new user.
|
||||
* Incoming requests using unexpired OAuth2 token correctly in authentication header should be able
|
||||
to successfully authenticate themselves.
|
||||
* Token scope mask over RBAC should work as described.
|
||||
* Tower configuration setting `OAUTH2_PROVIDER` should be configurable and function as described.
|
||||
* `/api/o/` endpoint should work as expected. In specific, all examples given in the description
|
||||
help text should be working (a user following the steps should get expected result).
|
||||
@@ -0,0 +1,88 @@
|
||||
# SAML
|
||||
Security Assertion Markup Language, or SAML, is an open standard for exchanging authentication and/or authorization data between an identity provider (*i.e.*, LDAP) and a service provider (*i.e.*, AWX). More concretely, AWX can be configured to talk with SAML in order to authenticate (create/login/logout) users of AWX. User Team and Organization membership can be embedded in the SAML response to AWX.
|
||||
|
||||
|
||||
# Configure SAML Authentication
|
||||
Please see the [Tower documentation](https://docs.ansible.com/ansible-tower/latest/html/administration/ent_auth.html#saml-authentication-settings) as well as the [Ansible blog post](https://www.ansible.com/blog/using-saml-with-red-hat-ansible-tower) for basic SAML configuration. Note that AWX's SAML implementation relies on `python-social-auth` which uses `python-saml`. AWX exposes three fields which are directly passed to the lower libraries:
|
||||
* `SOCIAL_AUTH_SAML_SP_EXTRA` is passed to the `python-saml` library configuration's `sp` setting.
|
||||
* `SOCIAL_AUTH_SAML_SECURITY_CONFIG` is passed to the `python-saml` library configuration's `security` setting.
|
||||
* `SOCIAL_AUTH_SAML_EXTRA_DATA`
|
||||
See http://python-social-auth-docs.readthedocs.io/en/latest/backends/saml.html#advanced-settings for more information.
|
||||
|
||||
|
||||
# Configure SAML for Team and Organization Membership
|
||||
AWX can be configured to look for particular attributes that contain AWX Team and Organization membership to associate with users when they log in to AWX. The attribute names are defined in AWX settings. Specifically, the authentication settings tab and SAML sub category fields *SAML Team Attribute Mapping* and *SAML Organization Attribute Mapping*. The meaning and usefulness of these settings is best communicated through example.
|
||||
|
||||
### Example SAML Organization Attribute Mapping
|
||||
|
||||
Below is an example SAML attribute that embeds user organization membership in the attribute *member-of*.
|
||||
```
|
||||
<saml2:AttributeStatement>
|
||||
<saml2:Attribute FriendlyName="member-of" Name="member-of" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
|
||||
<saml2:AttributeValue>Engineering</saml2:AttributeValue>
|
||||
<saml2:AttributeValue>IT</saml2:AttributeValue>
|
||||
<saml2:AttributeValue>HR</saml2:AttributeValue>
|
||||
<saml2:AttributeValue>Sales</saml2:AttributeValue>
|
||||
</saml2:Attribute>
|
||||
<saml2:Attribute FriendlyName="administrator-of" Name="administrator-of" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:unspecified">
|
||||
<saml2:AttributeValue>IT</saml2:AttributeValue>
|
||||
<saml2:AttributeValue>HR</saml2:AttributeValue>
|
||||
</saml2:Attribute>
|
||||
</saml2:AttributeStatement>
|
||||
```
|
||||
Below, the corresponding AWX configuration:
|
||||
```
|
||||
{
|
||||
"saml_attr": "member-of",
|
||||
"saml_admin_attr": "administrator-of",
|
||||
"remove": true,
|
||||
'remove_admins': true
|
||||
}
|
||||
```
|
||||
**saml_attr:** The SAML attribute name where the organization array can be found.
|
||||
|
||||
**remove:** Set this to `true` to remove a user from all organizations before adding the user to the list of Organizations. Set it to `false` to keep the user in whatever Organization(s) they are in while adding the user to the Organization(s) in the SAML attribute.
|
||||
|
||||
**saml_admin_attr:** The SAML attribute name where the organization administrators' array can be found.
|
||||
|
||||
**remove_admins:** Set this to `true` to remove a user from all organizations that they are administrators of before adding the user to the list of Organizations admins. Set it to `false` to keep the user in whatever Organization(s) they are in as admin while adding the user as an Organization administrator in the SAML attribute.
|
||||
|
||||
### Example SAML Team Attribute Mapping
|
||||
Below is another example of a SAML attribute that contains a Team membership in a list:
|
||||
```
|
||||
<saml:AttributeStatement>
|
||||
<saml:Attribute
|
||||
xmlns:x500="urn:oasis:names:tc:SAML:2.0:profiles:attribute:X500"
|
||||
x500:Encoding="LDAP"
|
||||
NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:uri"
|
||||
Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.1"
|
||||
FriendlyName="eduPersonAffiliation">
|
||||
<saml:AttributeValue
|
||||
xsi:type="xs:string">member</saml:AttributeValue>
|
||||
<saml:AttributeValue
|
||||
xsi:type="xs:string">staff</saml:AttributeValue>
|
||||
</saml:Attribute>
|
||||
</saml:AttributeStatement>
|
||||
```
|
||||
|
||||
```
|
||||
{
|
||||
"saml_attr": "eduPersonAffiliation",
|
||||
"remove": true,
|
||||
"team_org_map": [
|
||||
{
|
||||
"team": "member",
|
||||
"organization": "Default1"
|
||||
},
|
||||
{
|
||||
"team": "staff",
|
||||
"organization": "Default2"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
**saml_attr:** The SAML attribute name where the team array can be found.
|
||||
|
||||
**remove:** Set this to `true` to remove user from all Teams before adding the user to the list of Teams. Set this to `false` to keep the user in whatever Team(s) they are in while adding the user to the Team(s) in the SAML attribute.
|
||||
|
||||
**team_org_map:** An array of dictionaries of the form `{ "team": "<AWX Team Name>", "organization": "<AWX Org Name>" }` which defines mapping from AWX Team -> AWX Organization. This is needed because the same named Team can exist in multiple Organizations in Tower. The organization to which a team listed in a SAML attribute belongs to would be ambiguous without this mapping.
|
||||
@@ -0,0 +1,87 @@
|
||||
## Introduction
|
||||
|
||||
Before Tower 3.3, an auth token was used as the main authentication method. Starting from Tower 3.3,
|
||||
session-based authentication will take its place as the main authentication method, and auth token
|
||||
will be replaced by OAuth 2 tokens.
|
||||
|
||||
Session authentication is a safer way of utilizing HTTP(S) cookies. Theoretically, the user can provide authentication information, like username and password, as part of the
|
||||
`Cookie` header, but this method is vulnerable to cookie hijacks, where crackers can see and steal user
|
||||
information from the cookie payload.
|
||||
|
||||
Session authentication, on the other hand, sets a single `session_id` cookie. The `session_id`
|
||||
is *a random string which will be mapped to user authentication informations by server*. Crackers who
|
||||
hijack cookies will only get the `session_id` itself, which does not imply any critical user info, is valid only for
|
||||
a limited time, and can be revoked at any time.
|
||||
|
||||
> Note: The CSRF token will by default allow HTTP. To increase security, the `CSRF_COOKIE_SECURE` setting should
|
||||
be set to True.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
In session authentication, users log in using the `/api/login/` endpoint. A GET to `/api/login/` displays the
|
||||
login page of API browser:
|
||||
|
||||

|
||||
|
||||
Users should enter correct username and password before clicking on the 'LOG IN' button, which fires a POST
|
||||
to `/api/login/` to actually log the user in. The return code of a successful login is 302, meaning upon
|
||||
successful login, the browser will be redirected; the redirected destination is determined by the `next` form
|
||||
item described below.
|
||||
|
||||
It should be noted that the POST body of `/api/login/` is *not* in JSON, but in HTTP form format. Four items should
|
||||
be provided in the form:
|
||||
* `username`: The username of the user trying to log in.
|
||||
* `password`: The password of the user trying to log in.
|
||||
* `next`: The path of the redirect destination, in API browser `"/api/"` is used.
|
||||
* `csrfmiddlewaretoken`: The CSRF token, usually populated by using Django template `{% csrf_token %}`.
|
||||
|
||||
The `session_id` is provided as a return `Set-Cookie` header. Here is a typical one:
|
||||
```
|
||||
Set-Cookie: sessionid=lwan8l5ynhrqvps280rg5upp7n3yp6ds; expires=Tue, 21-Nov-2017 16:33:13 GMT; httponly; Max-Age=1209600; Path=/
|
||||
```
|
||||
Any client should follow the standard rules of [cookie protocol](https://tools.ietf.org/html/rfc6265) to
|
||||
parse that header to obtain information about the session, such as session cookie name (`session_id`),
|
||||
session cookie value, expiration date, duration, etc.
|
||||
|
||||
The duration of the cookie is configurable by Tower Configuration setting `SESSION_COOKIE_AGE` under
|
||||
category `authentication`. It is an integer denoting the number of seconds the session cookie should
|
||||
live. The default session cookie age is two weeks.
|
||||
|
||||
After a valid session is acquired, a client should provide the `session_id` as a cookie for subsequent requests
|
||||
in order to be authenticated. For example:
|
||||
```
|
||||
Cookie: sessionid=lwan8l5ynhrqvps280rg5upp7n3yp6ds; ...
|
||||
```
|
||||
|
||||
User should use the `/api/logout/` endpoint to log out. In the API browser, a logged-in user can do that by
|
||||
simply clicking logout button on the nav bar. Under the hood, the click issues a GET to `/api/logout/`.
|
||||
Upon success, the server will invalidate the current session and the response header will indicate for the client
|
||||
to delete the session cookie. The user should no longer try using this invalid session.
|
||||
|
||||
The duration of a session is constant. However, a user can extend the expiration date of a valid session
|
||||
by performing session acquire with the session provided.
|
||||
|
||||
A Tower configuration setting, `SESSIONS_PER_USER` under category `authentication`, is used to set the
|
||||
maximum number of valid sessions a user can have at the same time. For example, if `SESSIONS_PER_USER`
|
||||
is set to three and the same user is logged in from five different places, the earliest two sessions created will be invalidated. Tower will try
|
||||
broadcasting, via websocket, to all available clients. The websocket message body will contain a list of
|
||||
invalidated sessions. If a client finds its session in that list, it should try logging out.
|
||||
|
||||
Unlike tokens, sessions are meant to be short-lived and UI-only; therefore, whenever a user's password
|
||||
is updated, all sessions she owned will be invalidated and deleted.
|
||||
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
* Users should be able to log in via the `/api/login/` endpoint by correctly providing all necessary fields.
|
||||
* Logged-in users should be able to authenticate themselves by providing correct session auth info.
|
||||
* Logged-in users should be able to log out via `/api/logout/`.
|
||||
* The duration of a session cookie should be configurable by `SESSION_COOKIE_AGE`.
|
||||
* The maximum number of concurrent login for one user should be configurable by `SESSIONS_PER_USER`,
|
||||
and over-limit user sessions should be warned by websocket.
|
||||
* When a user's password is changed, all her sessions should be invalidated and deleted.
|
||||
* User should not be able to authenticate by HTTPS(S) request nor websocket connection using invalid
|
||||
sessions.
|
||||
* No existing behavior, like job runs, inventory updates or callback receiver, should be affected
|
||||
by session auth.
|
||||
@@ -0,0 +1,49 @@
|
||||
# TACACS+
|
||||
[Terminal Access Controller Access-Control System Plus (TACACS+)](https://en.wikipedia.org/wiki/TACACS) is a protocol developed by Cisco to handle remote authentication and related services for networked access control through a centralized server. In specific, TACACS+ provides authentication, authorization and accounting (AAA) services. Ansible Tower currently utilizes its authentication service.
|
||||
|
||||
TACACS+ is configured by Tower configuration and is available under `/api/v2/settings/tacacsplus/`. Here is a typical configuration with every configurable field included:
|
||||
```
|
||||
{
|
||||
"TACACSPLUS_HOST": "127.0.0.1",
|
||||
"TACACSPLUS_PORT": 49,
|
||||
"TACACSPLUS_SECRET": "secret",
|
||||
"TACACSPLUS_SESSION_TIMEOUT": 5,
|
||||
"TACACSPLUS_AUTH_PROTOCOL": "ascii"
|
||||
}
|
||||
```
|
||||
Each field is explained below:
|
||||
|
||||
| Field Name | Field Value Type | Field Value Default | Description |
|
||||
|------------------------------|---------------------|---------------------|--------------------------------------------------------------------|
|
||||
| `TACACSPLUS_HOST` | String | '' (empty string) | Hostname of TACACS+ server. Empty string disables TACACS+ service. |
|
||||
| `TACACSPLUS_PORT` | Integer | 49 | Port number of TACACS+ server. |
|
||||
| `TACACSPLUS_SECRET` | String | '' (empty string) | Shared secret for authenticating to TACACS+ server. |
|
||||
| `TACACSPLUS_SESSION_TIMEOUT` | Integer | 5 | TACACS+ session timeout value in seconds. |
|
||||
| `TACACSPLUS_AUTH_PROTOCOL` | String with choices | 'ascii' | The authentication protocol used by TACACS+ client (choices are `ascii` and `pap`). |
|
||||
|
||||
Under the hood, Tower uses [open-source TACACS+ python client](https://github.com/ansible/tacacs_plus) to communicate with the remote TACACS+ server. During authentication, Tower passes username and password to TACACS+ client, which packs up auth information and sends it to the TACACS+ server. Based on what the server returns, Tower will invalidate login attempt if authentication fails. If authentication passes, Tower will create a user if she does not exist in database, and log the user in.
|
||||
|
||||
## Test Environment Setup
|
||||
|
||||
The suggested TACACS+ server for testing is [shrubbery TACACS+ daemon](http://www.shrubbery.net/tac_plus/). It is supposed to run on a CentOS machine. A verified candidate is CentOS 6.3 AMI in AWS EC2 Community AMIs (search for `CentOS 6.3 x86_64 HVM - Minimal with cloud-init aws-cfn-bootstrap and ec2-api-tools`). Note that it is required to keep TCP port 49 open, since it's the default port used by the TACACS+ daemon.
|
||||
|
||||
We provide [a playbook](https://github.com/jangsutsr/ansible-role-tacacs) to install a working TACACS+ server. Here is a typical test setup using the provided playbook:
|
||||
|
||||
1. In AWS EC2, spawn the CentOS 6 machine.
|
||||
2. In Tower, create a test project using the stand-alone playbook inventory.
|
||||
3. In Tower, create a test inventory with the only host to be the spawned CentOS machine.
|
||||
4. In Tower, create and run a job template using the created project and inventory with parameters setup as below:
|
||||
|
||||

|
||||
|
||||
The playbook creates a user named 'tower' with ascii password default to 'login' and modifiable by `extra_var` `ascii_password` and pap password default to 'papme' and modifiable by `extra_var` `pap_password`. In order to configure TACACS+ server to meet custom test needs, we need to modify server-side file `/etc/tac_plus.conf` and `sudo service tac_plus restart` to restart the daemon. Details on how to modify config file can be found [here](http://manpages.ubuntu.com/manpages/xenial/man5/tac_plus.conf.5.html).
|
||||
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
* All specified Tower configuration fields should be shown and configurable as documented.
|
||||
* A user defined by the TACACS+ server should be able to log into Tower.
|
||||
* User not defined by TACACS+ server should not be able to log into Tower via TACACS+.
|
||||
* A user existing in TACACS+ server but not in Tower should be created after the first successful log in.
|
||||
* TACACS+ backend should stop an authentication attempt after configured timeout and should not block the authentication pipeline in any case.
|
||||
* If exceptions occur on TACACS+ server side, the exception details should be logged in Tower, and Tower should not authenticate that user via TACACS+.
|
||||
Reference in New Issue
Block a user