This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into bump-jackson-micro
- Loading branch information
Showing
15 changed files
with
165 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// Module included in the following assemblies: | ||
// | ||
// assembly-iot-creating-device.adoc | ||
|
||
[id='proc-iot-management-token-{context}'] | ||
= Obtaining an authentication token | ||
|
||
To access the device management API, you must obtain a token to authenticate yourself | ||
to the API. | ||
|
||
Access to an IoT tenant's devices is mapped by the device registry based on access to | ||
the `IoTProject` resource. If an account has *read* access to the `IoTProject`, this | ||
account can also execute *read* operations on the device registry for this IoT tenant. | ||
|
||
The token has to be presented to the API as a *bearer token* by adding | ||
an HTTP header value: `Authorization: Bearer <token>`. For more information, | ||
see link:https://tools.ietf.org/html/rfc6750[RFC 6750]. | ||
|
||
In the following configuration examples, replace `${TOKEN}` with the actual token. | ||
|
||
== Obtaining an authentication token for a user | ||
|
||
If you want to use the token of the current {KubePlatform}, you can extract the | ||
token. | ||
|
||
.Prerequisites | ||
|
||
* You must be logged in to your {KubePlatform} instance as a user that supports tokens. | ||
|
||
.Procedure | ||
|
||
. Extract the token for the current user: | ||
+ | ||
[options="nowrap",subs="+quotes,attributes"] | ||
---- | ||
ifeval::["{cmdcli}" == "oc"] | ||
oc whoami -t | ||
endif::[] | ||
ifeval::["{cmdcli}" == "kubectl"] | ||
kubectl config view -o json| jq -r '.users[] as $users | ."current-context" as $ctx | .contexts[] | select (.name==$ctx).context.user as $user | $users | select (.name==$user).user.token' | ||
endif::[] | ||
---- | ||
|
||
NOTE: User tokens have a limited lifetime, so it may be necessary | ||
to renew the token after it has expired. | ||
|
||
== Obtaining an authentication token for a service account | ||
|
||
Perform the following steps to create a new service account and extract the token. | ||
|
||
.Prerequisites | ||
|
||
* You must be logged in to your {KubePlatform} instance with permissions to create new service accounts, roles and role bindings. | ||
|
||
.Procedure | ||
|
||
. Create a new service account: | ||
+ | ||
[source,yaml,options="nowrap"] | ||
---- | ||
apiVersion: v1 | ||
kind: ServiceAccount | ||
metadata: | ||
name: my-device-manager-account # <1> | ||
---- | ||
<1> The name of the service account. | ||
|
||
. Create a new role, allowing access to the `IoTProject`: | ||
+ | ||
[source,yaml,options="nowrap"] | ||
---- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: Role | ||
metadata: | ||
name: device-manager-role # <1> | ||
rules: # <2> | ||
- apiGroups: ["iot.enmasse.io"] | ||
resources: ["iotprojects"] | ||
verbs: ["create", "update", "get", "list", "delete"] | ||
---- | ||
<1> The name of the role. | ||
<2> The access rules, which must grant CRUD access to the `IoTProject`. | ||
+ | ||
This example grants access to all `IoTProjects`s in a namespace. | ||
To further restrict access, use more specific rules. | ||
|
||
. Create a new role binding, assigning the role to the service account: | ||
+ | ||
[source,yaml,options="nowrap"] | ||
---- | ||
apiVersion: rbac.authorization.k8s.io/v1 | ||
kind: RoleBinding | ||
metadata: | ||
name: my-device-manager-account-role-binding | ||
roleRef: | ||
apiGroup: rbac.authorization.k8s.io | ||
kind: Role | ||
name: device-manager-role # <1> | ||
subjects: | ||
- kind: ServiceAccount | ||
name: my-device-manager-account # <2> | ||
---- | ||
<1> The name of the role. | ||
<2> The name of the service account. | ||
|
||
. Retrieve the token from the service account: | ||
+ | ||
[options="nowrap",subs="+quotes,attributes"] | ||
---- | ||
ifeval::["{cmdcli}" == "oc"] | ||
oc serviceaccounts get-token my-device-manager-account | ||
endif::[] | ||
ifeval::["{cmdcli}" == "kubectl"] | ||
kubectl get secret $(kubectl get sa my-device-manager-account -o json | jq -r '.secrets[] | select(.name | contains("-token-")).name') -o json | jq -r .data.token | ||
endif::[] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters