RESTCONF by Example

On this page

The Curity Identity Server uses a configuration database to store identity-related settings. You can use the RESTCONF API to programmatically read configuration or automate changes to it. The Introduction to the RESTCONF Admin API provides a video overview of calling the RESTCONF API. This tutorial takes you a little deeper, so that you understand addressability, prefixes, payloads and API security.

Local Computer Prerequisites

To run the commands in this tutorial, you need Docker and the command line utilities curl and jq.

Deploy the Curity Identity Server

A simple way to get started with the Curity Identity Server is to first run the Install using Docker. Then, complete the First Configuration, select All Options, and accept all default values. Make sure you import a license file, so that you get working endpoints.

Once the deployment completes, you can sign in to the Admin UI at https://localhost:6749/admin with your ADMIN_PASSWORD. Navigate to System → Deployment → Admin Service and notice that the basic setup wizard enables use of the RESTCONF API with basic authentication.

RESCONF API defaults to basic authentication

Get Connected to the RESTCONF API

Open another terminal window and set environment variables. To form the RESTCONF base URL, append /api/restconf to the Admin UI's base URL.

bash
12
export ADMIN_PASSWORD=Password1
export RESTCONF_BASE_URL='https://localhost:6749/admin/api/restconf/data'

You can then connect to the RESTCONF API with basic authentication, again using your admin user account and the ADMIN_PASSWORD. The following command downloads full RESTCONF information using the default XML format.

bash
123
export RESTCONF_BASE_URL='https://localhost:6749/admin/api/restconf/data'
curl -sk "$RESTCONF_BASE_URL" \
-u "admin:$ADMIN_PASSWORD" | more

Configuration Standards

The RESTCONF API for the Curity Identity Server implements the RESTCONF protocol as specified in RFC 8040 and the YANG data modeling language from RFC 7950.

Use Queries

Each identity resource has an addressable REST location. The following query returns all information about the default profiles that the first configuration creates. The result contains many nested objects.

bash
123
curl -sk "$RESTCONF_BASE_URL/base:profiles" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json"

Wire Formats

By default, the Curity’s RESTCONF API returns XML responses, with a content-type of application/yang-data+xml. You can request a JSON response, using an HTTP Accept header of application/yang-data+json. JSON requests and responses can sometimes be more concise than XML, and easier to program.

The response has the following structure. The first inner element always requires a prefix, to indicate the base YANG module https://curity.se/ns/conf/base.

json
1234567
{
"base:profiles": {
"profile": [
...
]
}
}

If you omit the base prefix in requests for the profiles element, you get a RESTCONF error response, which informs the caller that profiles requires a prefix.

json
1234567891011
{
"ietf-restconf:errors": {
"error": [
{
"error-type": "application",
"error-tag": "missing-attribute",
"error-message": "missing module name for 'profiles'"
}
]
}
}

To reduce content to just the data a RESTCONF client needs, use the depth parameter to restrict the number of levels in the response.

bash
123
curl -sk "$RESTCONF_BASE_URL/base:profiles/profile/?depth=3" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json"

You then see the following subset of elements. The following sections use this manageable payload to teach query techniques.

json
1234567891011121314151617181920212223242526272829303132333435363738394041424344
{
"base:profile": [
{
"id": "Applications",
"type": "profile-apps:apps-service",
"settings": {
"profile-apps:apps-service": {
}
},
"endpoints": {
"endpoint": [
]
}
},
{
"id": "authentication-service",
"type": "profile-authentication:authentication-service",
"settings": {
"profile-authentication:authentication-service": {
}
},
"endpoints": {
"endpoint": [
]
}
},
{
"id": "token-service",
"type": "profile-oauth:oauth-service",
"settings": {
"profile-oauth:authorization-server": {
}
},
"endpoints": {
"endpoint": [
]
},
"token-issuers": {
"default-token-issuer": {
}
}
}
]
}

The following query selects the token profile using the keys from the Profile Configuration Reference. It uses keys from the parent profiles resource, which are id=token-service and key=profile-oauth:oauth-service. Next, the query concatenates values with a comma separator, without prefixes, to form the selector token-service,oauth-service. The following example query also shows how to use the fields query string parameter to only return a response with the id and settings fields.

bash
123
curl -sk "$RESTCONF_BASE_URL/base:profiles/profile=token-service,oauth-service/?depth=4&fields=id;settings" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json"

The output then returns only the id and settings fields of the selected profile element to the RESTCONF client. The depth=4 parameter includes the immediate children of the settings field.

json
123456789101112131415161718192021222324252627282930313233343536
{
"base:profile": [
{
"id": "token-service",
"settings": {
"profile-oauth:authorization-server": {
"authentication-service": {
"authentication-profile": "authentication-service"
},
"client-capabilities": {
"code": {
},
"implicit": {
},
"client-credentials": {
},
"introspection": {
},
"oauth-token-exchange": {
}
},
"scopes": {
},
"claims": {
"claims-mappers": {
}
},
"openid-connect": {
"expose-metadata": {
}
}
}
}
}
]
}

Locating Key Fields

Whenever you need to specify a particular item within a collection, browse the configuration reference for the parent resource, to locate item key fields. Often, there is a single key named id. When the names of key fields are not obvious, GET requests against the collection resource can be a quick way to locate them.

Some child elements use prefixes to signify switching to a new YANG data model. For example, the Curity Identity Server supports many data sources, where only a subset uses JDBC. The configuration schema models JDBC as its own domain, with a separate YANG module. To see the use of prefixes, use RESTCONF to select the configuration's data-sources collection.

bash
123
curl -sk "$RESTCONF_BASE_URL/base:facilities/data-sources" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json"

Notice that the jdbc child element also uses a jdbc prefix, to indicate the new YANG data model.

json
1234567891011121314151617
{
"base:data-sources": {
"data-source": [
{
"id": "default-datasource",
"jdbc:jdbc": {
"connection-string": "data:text/plain;aes ...",
"standard-credentials-mode": {
},
"driver": "org.hsqldb.jdbc.JDBCDriver",
"password": "data:text/plain;aes ...",
"username": "SA"
}
}
]
}
}

Therefore, if you select the jdbc element you must also use the jdbc prefix, as the following query demonstrates.

json
123
curl -sk "$RESTCONF_BASE_URL/base:facilities/data-sources/data-source=default-datasource/jdbc:jdbc" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json"

Locating Prefixes

To understand when to use prefixes, do a GET request on the parent object. If a child element uses a prefix, use that prefix when you need to query the child element directly.

Use Data Changing Commands

You can use RESTCONF HTTP requests to automate configuration updates. Use HTTP POST to create an item. As an example, start with adding a new accounts scope to the token service. Store the request payload in a file for simplicity. Then submit the data to the RESTCONF API. See the Scope Configuration Reference to understand properties for the request payload.

bash
12345678910111213
jq -n \
'{
scope: {
id: "accounts",
description: "User accounts"
}
}' > scope.json
curl -sk -X POST "$RESTCONF_BASE_URL/base:profiles/profile=token-service,oauth-service/settings/profile-oauth:authorization-server/scopes" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json" \
-H "Content-Type: application/yang-data+json" \
-d @scope.json

To update an existing item, send an HTTP PATCH request. The following commands use an HTTP PATCH to exclude the scope from published metadata, without changing other properties.

bash
12345678910111213
jq -n \
'{
scope: {
id: "accounts",
"expose-in-metadata": false
}
}' > scope.json
curl -sk -X PATCH "$RESTCONF_BASE_URL/base:profiles/profile=token-service,oauth-service/settings/profile-oauth:authorization-server/scopes/scope=accounts" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json" \
-H "Content-Type: application/yang-data+json" \
-d @scope.json

To completely replace an existing item, send an HTTP PUT request. The following commands use an HTTP PUT to update the description, which also resets the expose-in-metadata property to its default value.

bash
12345678910111213
jq -n \
'{
scope: {
id: "accounts",
description: "Access to user accounts"
}
}' > scope.json
curl -sk -X PUT "$RESTCONF_BASE_URL/base:profiles/profile=token-service,oauth-service/settings/profile-oauth:authorization-server/scopes/scope=accounts" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json" \
-H "Content-Type: application/yang-data+json" \
-d @scope.json

To completely remove an existing item, send an HTTP DELETE request. The following command uses HTTP DELETE to permanently remove the scope.

bash
123
curl -sk -X DELETE "$RESTCONF_BASE_URL/base:profiles/profile=token-service,oauth-service/settings/profile-oauth:authorization-server/scopes/scope=accounts" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json"

You can follow similar techniques to work with other identity resources. For example, the following commands use fields from the Authenticator Configuration Reference to add an authenticator that uses usernames and passwords:

bash
123456789101112131415
jq -n \
'{
authenticator: {
id: "username-password",
"authenticator-html-form:html-form": {
"credential-manager": "default-credential-manager",
}
}
}' > authenticator.json
curl -sk -X POST "$RESTCONF_BASE_URL/base:profiles/profile=authentication-service,authentication-service/settings/profile-authentication:authentication-service/authenticators" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json" \
-H "Content-Type: application/yang-data+json" \
-d @authenticator.json

The following commands use fields from the Client Configuration Reference to add a client:

bash
123456789101112131415161718192021222324
jq -n \
'{
client: {
id: "web-client",
capabilities: {
code: {
}
},
"no-authentication": true,
"redirect-uris": ["https://www.demo.example"],
"proof-key": {
"require-proof-key": true,
},
scope: ["openid", "profile"],
"refresh-token-ttl": "disabled",
"validate-port-on-loopback-interfaces": true,
}
}' > client.json
curl -sk -X POST "$RESTCONF_BASE_URL/base:profiles/profile=token-service,oauth-service/settings/profile-oauth:authorization-server/client-store/config-backed" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json" \
-H "Content-Type: application/yang-data+json" \
-d @client.json

Some data changing commands require entities that span multiple YANG modules. The following example patches the default data source to use a PostgreSQL database with durable storage. To do so, it uses elements from the JDBC Configuration Reference, and the jdbc parent element requires a jdbc prefix.

bash
1234567891011121314151617181920
jq -n \
'{
"data-source": {
id: "default-datasource",
"jdbc:jdbc": {
driver: "org.postgresql.Driver",
"connection-string": "jdbc:postgresql://dbserver:5432/curitydb",
username: "curityuser",
password: "Password1",
"standard-credentials-mode": {
}
}
}
}' > datasource.json
curl -sk -X PATCH "$RESTCONF_BASE_URL/base:facilities/data-sources/data-source=default-datasource" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+json" \
-H "Content-Type: application/yang-data+json" \
-d @datasource.json

RESTCONF and Secrets

When you use RESTCONF to set secrets, you can use unencrypted values and the Curity Identity Server automatically encrypts them.

Use Complex Updates

You can use RESTCONF for more complex updates, for example, to activate new security features. One way to quickly learn payload formats is to make changes in the Admin UI and then Export the Configuration and inspect XML. Then, use XML snippets from the exported configuration in RESTCONF updates.

For example, you can use RESTCONF to activate the use of user management APIs. Start with an Authorization Manager that controls access to user management APIs. The following example RESTCONF operation adds an authorization manager that requires an accounts scope.

bash
1234567891011121314151617181920212223242526272829303132333435363738
cat << EOF > authorization-manager.xml
<authorization-manager>
<id>default</id>
<attribute xmlns="https://curity.se/ns/ext-conf/attribute">
<rule-list>
<name>user-access</name>
<description>A rule list for user account API access</description>
<enforcement-restrictions>
<default-allow-read>true</default-allow-read>
<default-allow-write>true</default-allow-write>
<require-subject-match>false</require-subject-match>
</enforcement-restrictions>
<rule>
<name>default</name>
<access-operation>create</access-operation>
<access-operation>read</access-operation>
<access-operation>update</access-operation>
<access-operation>delete</access-operation>
<attribute>account</attribute>
<decision>allow</decision>
</rule>
<select-rule-list-when>
<context-requirement>user-management-scim</context-requirement>
<context-requirement>user-management-graphql</context-requirement>
<scope-requirement>
<scope>accounts</scope>
</scope-requirement>
</select-rule-list-when>
</rule-list>
</attribute>
</authorization-manager>
EOF
curl -sk -X POST "$RESTCONF_BASE_URL/base:processing/authorization-managers" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+xml" \
-H "Content-Type: application/yang-data+xml" \
-d @authorization-manager.xml

Next, you need to create a user profile that uses the authorization manager, add user API endpoints to the user profile, then add the endpoints to the environment. You could perform those operations individually, but the RESTCONF API also allows you to make a single transactional HTTP PATCH request, to merge changes into its root data location.

bash
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
cat << EOF > config-patch.xml
<data xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf">
<profiles xmlns="https://curity.se/ns/conf/base">
<profile>
<id>user-service</id>
<type xmlns:um="https://curity.se/ns/conf/profile/user-management">um:user-management-service</type>
<settings>
<user-management-service xmlns="https://curity.se/ns/conf/profile/user-management">
<api-authentication>
<oauth-service>token-service</oauth-service>
</api-authentication>
<authorization-manager>default</authorization-manager>
<user-account-data-source>default-datasource</user-account-data-source>
<token-data-source>default-datasource</token-data-source>
<credential-management>
<credential-manager>default-credential-manager</credential-manager>
</credential-management>
</user-management-service>
</settings>
<endpoints>
<endpoint>
<id>scim-users-service</id>
<uri>/scim</uri>
<endpoint-kind>um-api</endpoint-kind>
</endpoint>
<endpoint>
<id>graphql-users-service</id>
<uri>/graphql/Users</uri>
<endpoint-kind>um-graphql-api</endpoint-kind>
</endpoint>
</endpoints>
</profile>
</profiles>
<environments xmlns="https://curity.se/ns/conf/base">
<environment>
<services>
<service-role>
<id>default</id>
<endpoints>scim-users-service</endpoints>
<endpoints>graphql-users-service</endpoints>
</service-role>
</services>
</environment>
</environments>
</data>
EOF
curl -sk -X PATCH "$RESTCONF_BASE_URL" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+xml" \
-H "Content-Type: application/yang-data+xml" \
-d @config-patch.xml

For the Docker deployment, you could then call http://localhost:8443/scim/Users and http://localhost:8443/graphql/Users to operate on user accounts. The only authorized requests would be those with an access token that includes the accounts scope. To learn more about user management APIs, see the SCIM User Management and GraphQL User Management tutorials.

Upgrade to Access Tokens

The examples so far use the RESTCONF API with an HTTP basic credential. Once you get connected, you should secure RESTCONF requests with OAuth access tokens instead. To see how that works, run the following RESTCONF patch.

bash
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
cat << EOF > config-patch.xml
<data xmlns="urn:ietf:params:xml:ns:yang:ietf-restconf">
<profiles xmlns="https://curity.se/ns/conf/base">
<profile>
<id>token-service</id>
<type xmlns:as="https://curity.se/ns/conf/profile/oauth">as:oauth-service</type>
<settings>
<authorization-server xmlns="https://curity.se/ns/conf/profile/oauth">
<scopes>
<scope>
<id>urn:se:curity:scopes:admin:api</id>
<claims>groups</claims>
</scope>
</scopes>
<claims>
<claim>
<name>groups</name>
<no-source/>
<transformation>
<value-transformation-procedure>ZnVuY3Rpb24gZ2VuZXJhdGUoKSB7CiAgcmV0dXJuIFsiYWRtaW4iXQp9</value-transformation-procedure>
</transformation>
</claim>
<claims-mappers>
<claims-mapper>
<id>default</id>
<access_token>
<claim>groups</claim>
</access_token>
</claims-mapper>
</claims-mappers>
</claims>
<client-store>
<config-backed>
<client>
<id>restconf-client</id>
<secret>Password1</secret>
<scope>urn:se:curity:scopes:admin:api</scope>
<audience>urn:se:curity:audiences:admin:api</audience>
<capabilities>
<client-credentials/>
</capabilities>
</client>
</config-backed>
</client-store>
</authorization-server>
</settings>
</profile>
</profiles>
<environments xmlns="https://curity.se/ns/conf/base">
<environment>
<admin-service>
<http>
<restconf>
<basic-authentication>false</basic-authentication>
<oauth xmlns="https://curity.se/ns/conf/profile/oauth">
<oauth-profile>token-service</oauth-profile>
<client>restconf-client</client>
</oauth>
</restconf>
</http>
</admin-service>
</environment>
</environments>
</data>
EOF
curl -sk -X PATCH "$RESTCONF_BASE_URL" \
-u "admin:$ADMIN_PASSWORD" \
-H "Accept: application/yang-data+xml" \
-H "Content-Type: application/yang-data+xml" \
-d @config-patch.xml

The patch performs the following steps.

  • Creates the urn:se:curity:scopes:admin:api scope for RESTCONF access.
  • Adds a groups claim to the scope.
  • Uses a JavaScript transformation procedure that resolves the groups claim to a value.
  • Creates an OAuth client named restconf-client that uses the scope and the client credentials flow.
  • Updates the admin service so that RESTCONF requires OAuth access tokens.
  • Updates the admin service to allow restconf-client to call RESTCONF endpoints.

You can then run the following commands to get an access token and call the RESTCONF API.

bash
123456789
ACCESS_TOKEN=$(curl -s -X POST http://localhost:8443/oauth/v2/oauth-token \
-H 'Content-Type: application/x-www-form-urlencoded' \
-u 'restconf-client:Password1' \
-d 'grant_type=client_credentials' \
-d 'scope=urn:se:curity:scopes:admin:api' | jq -r .access_token)
curl -sk "$RESTCONF_BASE_URL/base:profiles/profile/?depth=3" \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Accept: application/yang-data+json"

At runtime, this example evaluates the groups claim from the base64 encoded JavaScript in the claim's transformation procedure. The JavaScript returns a string array with a single item named admin, so that the access token continues to grant administrator privileges to the RESTCONF API.

This example uses the client_credentials flow for simplicity, but a real deployment could configure the RESTCONF client to use the code flow. The transformation procedure could then evaluate the groups claim from a user attribute, and grant distinct levels of RESTCONF access to different user types. The Authorization Rules for the RESTCONF API tutorial explains more about permissions and assigning them to groups.

Summary

The RESTCONF API provides read and write access to the Curity Identity Server's configuration database. Use RESTCONF to automate resource updates and to activate new security features. Make sure you also harden access, to restrict allowed RESTCONF clients and users, and to limit privileges.

This tutorial explained the most common first steps with RESTCONF. You can learn much more in the RESTCONF Administration and Access Control docs.

Architecture

See how Curity fits into modern identity and API architectures.

Explore architecture

Customer Stories

Learn how organizations run identity and API security at scale.

Read customer stories