Policy

A policy enables developers to configure fine-grained access control for things and other entities in an easy way.

note The policy concept is only supported for Bosch IoT Thing HTTP API version 2.
Find the API reference at Policies resources.

Authorization concept

A specific policy provides someone (called subject), permission to read and/or write at a given resource.

tip The write permission at the policy root resource (i.e. “policy:/”) allows to manage the policy itself.
Find an example at the end of the page.

Please note, that in most cases it makes sense to grant read permission in addition to a write permission, because write does not imply read.

Who can be addressed

A subject can be a technical client or a user.

Example

{
  "subjects": {
     "iot-things:918904f5-xxxx-xxxx-xxxx-cb73a5ba9dbf:my-client":{
        "type": "iot-things-clientid"
     },
      "iot-permissions:8c36bc60-xxxx-xxxx-xxxx-4ed6ce7ed64c": {
        "type": "iot-permissions-userid"
      },
      "bosch:S-1-xxx@ciamids_36xxx": {
        "type": "bosch-id"
      }
  }
}             

Build-in subject ID pattern

Prefix / issuer (mandatory) ID (mandatory) Type (informational) Description Example
iot-things solutionId:your-postfix iot-things-clientid The ID of a technical client
(Java client and CRS authentication)
iot-things:123:my-app
iot-permissions user ID, group ID or role ID perm-user, perm-group, or perm-role The ID of a user, group, role
managed within Bosch IoT Permissions
iot-permissions:123
iot-permissions tenant-id\application-role-id iot-permissions-role The application role.
Subject is derived from a JWT issued by Bosch IoT Permissions which contains the arid claim.
Be aware that you will need to escape the backslash (\) with another one.
iot-permissions:123\456
bosch Bosch ID of user @ client ID bosch-id The ID of a Bosch account (Bosch ID) and the client ID separated by an at @ character.
Recommended notation.
bosch:S-1-2-3@456
bosch Bosch ID of user bosch-id The ID of a Bosch account (Bosch ID)
Not recommended any longer. Use the new notation with the client ID for production scenarios.
bosch:S-1-2-3
google UUID google-id The ID of a Google user google:123
integration solutionId:your-postfix hub, amqp, or mqtt The ID of a technical client, used for
receiving or publishing messages
over Connections
integration:123:hub
iot-suite Bosch ID of user / iot-things scope @ client ID suite-auth The ID of a Bosch account (Bosch ID).
The iot-things scope and client ID of the OAuth2 client managed at Bosch IoT Suite portal.
See https://accounts.bosch-iot-suite.com/oauth2-clients/
iot-suite:S-1-2-3/service-instance.4-5-6.iot-things@7-8-9
iot-suite /iot-things scope @ client ID suite-auth The iot-things scope and client ID of the OAuth2 client managed at Bosch IoT Suite portal.
Recommended notation.
See https://accounts.bosch-iot-suite.com/oauth2-clients/
iot-suite:/service-instance.4-5-6.iot-things@7-8-9
iot-suite Bosch ID of user / iot-things scope suite-auth The ID of a Bosch account (Bosch ID).
The iot-things scope of the OAuth2 client managed at Bosch IoT Suite portal.
See https://accounts.bosch-iot-suite.com/oauth2-clients/
iot-suite:S-1-2-3/service-instance.4-5-6.iot-things
iot-suite / iot-things scope suite-auth The iot-things scope of the OAuth2 client managed at Bosch IoT Suite portal.
See https://accounts.bosch-iot-suite.com/oauth2-clients/
iot-suite:/service-instance.4-5-6.iot-things
iot-suite client ID suite-auth The ID is the client ID of the OAuth2 client managed at Bosch IoT Suite portal.
See https://accounts.bosch-iot-suite.com/oauth2-clients/
Not recommended any longer. Use the new notation with scope and client ID for production scenarios.
iot-suite:/7-8-9
iot-suite iot-things-eu-1:service:123_things/full-access suite-auth The old scope notation which was previously found for OAuth2 clients managed at Bosch IoT Suite portal.
E.g. iot-suite:service:iot-things-eu-1:1-2-3_things/full-access See https://accounts.bosch-iot-suite.com/oauth2-clients/
Not recommended any longer. Use the new notation with the new scope and client ID for production scenarios.
The old scope format
service:iot-things-eu-1:1-2-3_things/full-access can be mapped to new format
service-instance.1-2-3.iot-things

The type is offered only for documentation purposes. You are not restricted to any specific types, but we recommend to use it to specify the kind of the subject as shown in our examples.

Custom subject of your OpenID Connect authentication provider

Upon request, the Things service team will configure your custom OpenID Connect authentication provider. See https://openid.net/connect/. We will need to know the specific URL of the issuer.

Prefix / issuer (mandatory) ID (mandatory) Type (informational) Description
Your will get a custom prefix Your custom IDs will be derived from the value of the external_sub claim e.g. <external_sub>/<scope> The type is offered only for documentation purposes. You are not restricted to any specific types. For each scope of the JWT, a subject with the format
<subject-issuer>:<external_sub>/<scope>@<client>
will be generated.

As a second step, you will need to register a client to your Bosch IoT Things subscription.
See APIdocs - PUT ​/solutions​/{solutionId}​/clients .

The type is offered only for documentation purposes. You are not restricted to any specific types, but we recommend to use it to specify the kind of the subject as shown in our examples.

Which resources can be controlled

A policy can contain access control definitions for several resources:

  • Policy
    Someone who was granted write permission at the policy root resource (i.e. policy:/) is allowed to manage the policy itself.
  • Thing
    The resource can be defined as rough or as fine-grained as necessary for the respective use case: e.g. “thing:/” as top-level resource, or on sub-resources such as “thing:/features”. At runtime, the permissions are propagated down to all thing sub-entities.
    • In case you grant read permission on top-level and revoke it at a sub-entity, the subject can read the upper part only.
    • In case you omit a subject at top-level but grant permission at a sub-entity, the subject can access the lower part only (and the thingId).
  • Message
    The resource can be defined as rough or as fine-grained as necessary for the respective use case: e.g. “message:/” as top-level resource.
  • Solution
    Someone who was granted write permission at the solution root resource (i.e. solution:/) is allowed to manage the solution itself. See Policy of a solution.

Policy

The policy resource (addressable as “policy:/”) defines the access control for the policy itself.

tip Please make sure to define at least one user (for which you have the credentials) with top-level read and write permissions on the policy, otherwise you won’t be able to access/change it.

Resource Addressed data, description
policy:/ The policy itself (top-level)
Applies to the Policy and all of its sub-resources.
policy:/policyId The ID of the policy.
However, such a reference is not recommended because write is not supported anyway,
and read on the ID only, does not provide any benefit.
policy:/entries Applies to all entries of the policy.
policy:/entries/X Applies to all subjects and resources of the specific entry X.
policy:/entries/X/subjects Applies to all subjects of the specific entry X.
policy:/entries/X/subjects/Y Applies to subject Y of the specific entry X.
policy:/entries/X/resources Applies to all resources of the specific entry X.
policy:/entries/X/resources/Y Applies to resource Y of the specific entry X.

Example: The example at the end of the page also defines access control on the policy resource.

Thing

The thing resource (addressable as “thing:/”) defines the access control for things.

tip In case you want to re-use a policy for various things, we recommend to name the policyId differently than the thingId.

Example:

{
  "thingId": "org.example:coffee-machine-01",
  "policyId": "org.example:coffee-machine-policy"
}

In case multiple things share the same policy, the settings at the thing:/ resource will be applied to all things referencing this policy.

Resource Addressed data, description
thing:/ The thing itself (top-level).
Applies to the thing and all of its sub-resources.
thing:/thingId The ID of the thing.
Not recommended, because write is not supported anyway and read on the ID only does not provide any benefit.
thing:/policyId Applies to the policy ID of the thing, which implicitly defines its access control.
Please double-check write permissions on this resource.
thing:/definition Applies to the definition field of the thing.
thing:/attributes Applies to all attributes of the thing.
thing:/attributes/X Applies to the specific attribute X and its sub-paths.
X may be a nested path such as tire/pressure.

Example: Find an example at the end of the page.

Feature

Resource Addressed data, description
thing:/features Applies to all features of the thing.
thing:/features/X Applies to the feature with ID X and all its sub-paths.
thing:/features/X/properties Applies to all properties of the feature X.
thing:/features/X/properties/Y Applies to the property with path Y (and its sub-paths) of the feature with ID X.
Y may be a nested path such as tire/pressure.

Example: Find an example at the end of the page.

Message

The message resource (addressable as “message:/”) defines the access control for messages.

The access control definitions will be applied to all messages sent to or from a thing referencing this policy.

  • For sending messages to a thing or its features write permission is required
  • For receiving messages from a thing or its features read permission is required.

Such permissions can be defined at resources of different granularity.

Resource Addressed data, description
message:/ All messages (top-level)
Applies to all messages sent to or from things referencing this policy
and all messages sent to or from features of these things.
message:/inbox Applies to all messages sent to a specific thing (or multiple things referencing this policy)
message:/inbox/messages/X Applies to all messages on message-subject X, sent to a thing referencing this policy
message:/outbox Applies to all messages sent from a thing referencing this policy
message:/outbox/messages/X Applies to all messages on message-subject X, sent from a thing referencing this policy
message:/features Messages for all features
Applies to all messages sent to or from all features of a thing referencing this policy
message:/features/Y Applies to all messages sent to or from feature Y of a things referencing this policy
message:/features/Y/inbox Applies to all messages sent to feature Y of a thing referencing this policy
message:/features/Y/inbox/messages/X Applies to all messages on message-subject X sent to feature Y of a thing referencing this policy
message:/features/Y/outbox Applies to all messages sent from feature Y of a thing referencing this policy
message:/features/Y/outbox/messages/X Applies to all messages on message-subject X sent from feature Y of a thing referencing this policy

tip The resources “message:/inbox” and “message:/outbox” do not address feature-related messages. For providing access to feature-related messages, you have to either grant top-level permission (message:/”) or grant permission to the resource message:/features” (or the required sub-resources).

Example: The example at the end of the page also defines access control on messages.

Solution

The solution resource (addressable as “solution:/”) defines the access control for your Bosch IoT Things service instance.

The solution policy defines the access rules for your solution.

note The solution policy ID is defined automatically by our service at the time of subscribing the service, thus you will not be able to set a different ID (e.g. like you could do it for a thing entity). Find your solution policy ID at the dashboard’s Basic data tab.

Resource Addressed data, description
solution:/ The solution itself (top-level).
Applies to the solution and all of its sub-resources.
solution:/key Applies to the public key of the solution.
solution:/namespaces Applies to all namespaces of the solution.
solution:/connections Applies to all connections of the solution.
solution:/connections/<connectionId> Applies to the specific connection with the given connectionId.
solution:/connections/<connectionId>/status Applies to the status of the specific connection with the given connectionId.
solution:/connections/<connectionId>/metrics Applies to all metrics of the specific connection with the given connectionId.
solution:/connections/<connectionId>/metrics/etc. Applies to specific metrics of the specific connection with the given connectionId.
solution:/connections/<connectionId>/logs Applies to all logs of the specific connection with the given connectionId.
solution:/connections/<connectionId>/logs/etc. Applies to specific log entries of the specific connection with the given connectionId.

tip Find an example at Policy of a solution.

Grant and revoke permission

Change Permission Description
grant READ All subjects named in the section are granted read permission on the resources specified in the path, and all subsequent paths, except they are revoked at a subsequent policy label.
grant WRITE All subjects named in the section are granted write permission on the resources specified in the path, and all subsequent paths, except they are revoked at a subsequent policy label.
revoke READ All subjects named in the section are prohibited to read on the resources specified in the path, and all subsequent paths, except they are granted again such permission at a subsequent policy label.
revoke WRITE All subjects named in the section are prohibited to write on the resources specified in the path, and all subsequent paths, except they are granted again such permission at a subsequent policy label.

Tools for editing a policy

The policy can be edited with a text editor of your choice. Just make sure it is in valid JSON representation, and that at least one valid subject is granted write permission at the root resources.

The easiest way is, to copy the model schema provided at the interactive HTTP API documentation, and adapt it to your needs.

In case of fine-grained access on things, keep an eye on your actual thing structure to make sure that all paths will be granted or revoked the permissions your use case is supposed to support.

Example

Given you need to support the following scenario:

  • Owner
    The thing my.namespace:thing-0123 is owned by a user. Thus, he needs full access and admin rights for the complete thing.
    In our example his ID is 8c36bc60-xxxx-xxxx-xxxx-4ed6ce7ed64c
  • Observer of changes at featureX and featureY
    • Another application needs to be informed on each change at those features.
      In our example its ID is eebbb40e-xxxx-xxxx-xxxx-f79a4653946b:observer-client.
    • There is a group of users who are allowed to read both features.
      In our example the group ID is 93f24210-xxxx-xxxx-xxxx-620a03644e93
  • Privacy
    • The value of the “city” property at “featureY” is confidential and needs to be “hidden” from the group of users.

policy-example

To accomplish all conditions mentioned above, your policy might look like the following image.

policy example

The correct JSON notation would be as shown in the following code block.

{
   "policyId": "my.namespace:policy-a",
   "entries": {
     "owner": {
       "subjects": {
         "iot-permissions:8c36bc60-xxxx-xxxx-xxxx-4ed6ce7ed64c": {
           "type": "iot-permissions-userid"
         }
       },
       "resources": {
         "thing:/": {
           "grant": ["READ", "WRITE"],
           "revoke": []
         },
         "policy:/": {
           "grant": ["READ", "WRITE"],
           "revoke": []
         },
         "message:/": {
           "grant": ["READ", "WRITE"],
           "revoke": []
         }
       }
     },
     "observer": {
       "subjects": {
         "iot-things:eebbb40e-xxxx-xxxx-xxxx-f79a4653946b:observer-client": {
           "type": "iot-things-clientid"
         },
         "iot-permissions:93f24210-xxxx-xxxx-xxxx-620a03644e93": {
           "type": "iot-permissions-groupid"
         }
       },
       "resources": {
         "thing:/features/featureX": {
           "grant": ["READ"],
           "revoke": []
         },
         "thing:/features/featureY": {
           "grant": ["READ"],
           "revoke": []
         }
       }
     },
     "private": {
       "subjects": {
         "iot-permissions:93f24210-xxxx-xxxx-xxxx-620a03644e93": {
           "type": "iot-permissions-groupid"
         }
       },
       "resources": {
         "thing:/features/featureX/properties/location/city": {
           "grant": [],
           "revoke": ["READ"]
         }
       }
     }
   }
 }

note The user ID, group ID and solution ID from the example above are just example values.

The policy can be found:

  • Via GET request at /api/2/policies/<policyId>, and
  • Via GET request at /api/2/things/{thingId}/policyId
  • At any thing itself in its JSON representation.
    A common get thing request, does not include the full policy by default, but you can be retrieve it by appending the field _policy as a query parameter e.g. /api/2/things/<thingId>?fields=_policy

In case of doubt add for each role an own “label” and later add the subject which you need to empower in the specific section.

Imprint Legal info Privacy statement