2.2. UDM HTTP REST API#
This section describes how to use the UDM HTTP REST API in Nubus. It addresses software developers and DevOps engineers. It covers the deployments for Kubernetes and the UCS appliance.
The UDM HTTP REST API provides a REST API to interact with directory objects through the Directory Manager in Nubus. It’s the only component in Nubus that allows packaged integrations and third-party applications to write to the directory service. The API provides create, read, update, and delete operations for directory objects, so-called CRUD operations. It’s accessible to Nubus components and third-party applications on the same cluster network. Nubus for Kubernetes uses the API during its installation to load initial data to the directory service. Packaged integrations use the UDM data loader to load additional data to the directory service.
As software developer you can use the UDM HTTP REST API, for example, to write a plugin for your application for CRUD operations towards Nubus.
Important
By default, the UDM HTTP REST API is accessible from inside and outside the cluster if not deactivated. The UDM HTTP REST API has no measures for brute force detection or multi-factor authentication.
In Nubus for Kubernetes,
to deactivate API access for services outside the Kubernetes cluster,
set the
nubusUdmRestApi.ingress.enabled
value in the Helm values file
from the default value true
to false
.
See also
- Directory Manager
in Univention Nubus for Kubernetes - Architecture Manual [1] for information about the architecture of the Directory Manager.
2.2.1. API location#
The UDM HTTP REST API provides an API endpoint for requests, an OpenAPI schema definition, and an interactive OpenAPI schema. Table 2.1 shows the endpoints for the UDM HTTP REST API.
Endpoint |
Interactive OpenAPI schema |
OpenAPI schema definition |
---|---|---|
|
|
|
The hostname depends on your deployment of Nubus: Nubus for Kubernetes or Nubus for UCS Appliance.
The value of global.domain
in your values file defines the domain of your cluster.
Table 2.2
shows the URL schema to the API endpoints
in Nubus for Kubernetes.
Replace $(domain)
with your value in global.domain
.
Endpoint |
Interactive OpenAPI schema |
---|---|
|
|
To download the OpenAPI schema,
use https://portal.$(domain)/univention/udm/openapi.json
.
- Examples
https://portal.example.com/univention/udm/
https://portal.example.com/univention/udm/schema/
https://portal.example.com/univention/udm/openapi.json
In this example, the hostname is
portal.example.com
.
The UCS Primary Directory Node has the UDM HTTP REST API installed. You need to use its hostname as FQDN for the following URL schema. Table 2.3 shows the URL schema to the API endpoints in Nubus in the UCS appliance.
Endpoint |
Interactive OpenAPI schema |
---|---|
|
|
To download the OpenAPI schema,
use https://$(FQDN)/univention/udm/openapi.json
.
- Examples
https://primary.example.com/univention/udm/
https://primary.example.com/univention/udm/schema/
https://primary.example.com/univention/udm/openapi.json
In this example, the hostname is
primary.example.com
.
2.2.2. Authentication#
To use the UDM HTTP REST API
you need to authenticate with a user account
that’s a member of Authorization groups.
By default, one of these user accounts is Administrator
.
The UDM HTTP REST API provides authentication
with user credentials through HTTP basic authentication.
Important
In JSON requests to the UDM HTTP REST API,
you always need to ensure to provide the additional header Accept: application/json
.
2.2.4. API methods#
You can interact with the API by sending HTTP requests to the appropriate API resources. Depending on the resource, different HTTP methods are available. Table 2.4 lists the HTTP methods. For the parameters, see the OpenAPI interactive schema. For a description of how to use the schema, see API location.
Method |
Description |
---|---|
|
To search, list, or get UDM objects. Example: Search for a user object. |
|
To create a UDM object. Example: Create a user object. |
|
To remove a UDM object. Example: Delete a user object. |
|
To modify the properties of a UDM object, or move the object into a different container. See Object modification with PATCH and PUT. Example: Modify a user object. |
|
To modify the properties of a UDM object. See Object modification with PATCH and PUT. Example: Modify a user object. |
For information about the differences between PATCH
and PUT
,
see Object modification with PATCH and PUT.
To ensure that the UDM HTTP REST API works on the same object from your initial request,
see Conditional requests with entity tags.
/univention/udm/<module>/<object>/
.- Examples
/univention/udm/users/user/
/univention/udm/groups/group/
/univention/udm/portals/entry/
Important
You need to manually restart the UDM HTTP REST API service, if you use the API to create, modify, or delete the following endpoints:
settings/extended_attribute
settings/udm_hook
settings/udm_module
settings/udm_syntax
settings/syntax
For Nubus for Kubernetes, run the commands as shown in Listing 2.10.
For Nubus for UCS appliance, run the commands as shown in Listing 2.15.
Note
To get a full list of resources and their available methods and parameters, browse the OpenAPI interactive schema. It’s available in any running Nubus installation. See API location. Listing all resources would exceed the document’s scope.
See also
- Internal functions
in Univention Nubus for Kubernetes - Architecture Manual [1] for more information about the Directory Manager.
2.2.4.1. Object modification with PATCH
and PUT
#
For object modification,
the UDM HTTP REST API offers the HTTP methods PATCH
and PUT
:
PATCH
With the
PATCH
HTTP method you can modify object properties, except the object’s distinguished name (DN). UsePATCH
, if you want to only change object properties.PUT
With the
PUT
HTTP method you modify and replace the whole object and move it to a different position in the directory service tree that changes the object’s distinguished name (DN). UsePUT
, if you want to modify the object’s position, of if you want to replace the object.
See also
For more information about the differences of these HTTP methods, see the following web pages:
- PATCH - HTTP | MDN
The
PATCH
HTTP method applies partial modifications to a resource.- PUT - HTTP | MDN
The
PUT
HTTP method creates a new resource or replaces a representation of the target resource with the request content.
2.2.5. API response codes#
Table 2.5 shows a non-exhaustive list of HTTP response codes that the UDM HTTP REST API uses to respond to requests.
Code |
Name |
Example case |
---|---|---|
400 |
Bad Request |
The API doesn’t understand the format of the request. The payload is most likely not in the format expected by the UDM HTTP REST API. |
401 |
Unauthorized |
The request provides no or wrong credentials for authorization, or the Directory Service isn’t available. |
403 |
Forbidden |
User isn’t part of any of the Authorization groups. |
404 |
Not Found |
The requested resource doesn’t exist. |
406 |
Not Acceptable |
The header field When you use JSON requests and expect JSON responses,
you need to set the |
412 |
Precondition Failed |
The header |
413 |
Payload Too Large |
The request payload contains a field that exceeds its size limit. |
416 |
Range Not Satisfiable |
In the request, the field |
422 |
Unprocessable Content |
The validation of input parameters failed. |
500 |
Internal Server Error |
Generic error code for internal server errors. In Nubus for Kubernetes, the UDM HTTP REST API pod’s log may contain more information. |
503 |
Service Unavailable |
The server for the service isn’t available. |
2.2.6. Usage examples#
This section shows examples for how to create, modify, search, and delete a user through the UDM HTTP REST API.
To follow along with the examples,
define environment variables as shown in
Listing 2.18.
The HOSTNAME
depends on your deployment.
For the respective value, see API location.
$ export HOSTNAME="<hostname to api>"
$ export USER="<username to userobject in authorization group>"
$ export PASSWORD="<password for the user>"
$ export MODULE="<UDM module to address>"
Note
When you go through the examples,
you see the _links
and _embedded
properties
in the responses.
HAL, the Hypertext Application Language, defines theses properties
and the API uses them.
The properties contain links for traversal through the API.
For more information on HAL,
refer to
JSON Hypertext Application Language.
For example, the _links
property of the response to a paginated query
contains the next
property pointing to the next page.
2.2.6.1. Templates for UDM modules#
The UDM modules in the UDM HTTP REST API provide templates in JSON format that help you to fill out the expected properties for requests. This section introduces templates for UDM modules, describes how you can retrieve them, and how to condense them for proper editing.
- Generic command
Listing 2.19 shows the generic command to retrieve a template. For the initialization of the used environment variables, see Listing 2.18.
$ curl \ --user ${USER}:${PASSWORD} \ --request GET \ --header "Accept: application/json" \ https://${HOSTNAME}/univention/udm/${MODULE}/add
- Template for
users/user
UDM module To retrieve the template for the
users/user
UDM module, use the commands in Listing 2.20.$ export MODULES="users/user" $ curl \ --user ${USER}:${PASSWORD} \ --request GET \ --header "Accept: application/json" \ https://${HOSTNAME}/univention/udm/${MODULE}/add
- Human-readable template
To make the template more readable and save it into a file, you can use Python as shown with the commands in Listing 2.21. The result is a file with more than 160 lines in properly formatted JSON.
$ export MODULES="users/user" $ curl \ --user ${USER}:${PASSWORD} \ --request GET \ --header "Accept: application/json" \ https://${HOSTNAME}/univention/udm/${MODULE}/add \ | python3 -m json.tool > user_template.json
- Condensed template without metadata
The JSON file contains metadata information in the keys that start with
_
. The metadata information isn’t necessary to create a user object. To filter out the metadata, use the command in Listing 2.22. The condensed template file has only more than 110 lines.$ export MODULES="users/user" $ curl \ --user ${USER}:${PASSWORD} \ --request GET \ --header "Accept: application/json" \ https://${HOSTNAME}/univention/udm/${MODULE}/add \ | python3 -c 'import sys, json; \ template = json.load(sys.stdin); \ template = {key:value for key, value in template.items() if not key.startswith("_")}; \ json.dump(template, sys.stdout, indent=4)' > user_template.json
2.2.6.2. Create a user object#
This example shows how to create a user object with a POST request to the UDM HTTP REST API.
Before you continue, download the UDM template for the
users/user
module as shown in Listing 2.22, and save the template in theuser_template.json
file.Copy the template file to the
user.json
file and edit the properties to suitably describe the user object that you want to create.To send the POST request and use the
user.json
as input for the user account properties, run the commands in Listing 2.23. For the initialization of the used environment variables, see Listing 2.18.$ export MODULES="users/user" $ curl \ --user ${USER}:${PASSWORD} \ --request POST \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --data @user.json \ https://${HOSTNAME}/univention/udm/${MODULE}/
2.2.6.3. Search for a user object#
This example shows a request to search for a user object,
whose username
property starts with "Admi"
.
Listing 2.24
shows the commands for the search request.
For the initialization of the used environment variables,
see
Listing 2.18.
$ export MODULES="users/user"
$ curl \
--user ${USER}:${PASSWORD} \
--request GET \
--header "Accept: application/json" \
"https://${HOSTNAME}/univention/udm/${MODULE}/?query\[username\]=Admi*"
Search result example
The result looks similar to
Listing 2.25.
It only shows the _embedded
section for brevity.
The omitted section is _links
.
"_embedded": {
"udm:object": [
{
"dn": "uid=Administrator,cn=users,dc=example,dc=com",
"objectType": "users/user",
"id": "Administrator",
"position": "cn=users,dc=example,dc=com",
"properties": {
"username": "Administrator",
"uidNumber": 2001,
"gidNumber": 5000,
"firstname": "Admin",
"lastname": "Administrator",
"gecos": "Admin Administrator",
"displayName": "Admin Administrator",
"title": null,
"initials": null,
"preferredDeliveryMethod": null,
"sambaPrivileges": [],
"description": null,
"organisation": null,
"userexpiry": null,
"passwordexpiry": null,
"pwdChangeNextLogin": false,
"preferredLanguage": null,
"disabled": false,
"accountActivationDate": {
"activation-date": null,
"activation-time": null,
"activation-timezone": "Etc/UTC"
},
"locked": false,
"lockedTime": "0",
"unlock": false,
"unlockTime": "",
"password": null,
"street": null,
"e-mail": [],
"postcode": null,
"postOfficeBox": [],
"city": null,
"country": null,
"state": null,
"phone": [],
"employeeNumber": null,
"roomNumber": [],
"secretary": [],
"departmentNumber": [],
"employeeType": null,
"homePostalAddress": [],
"physicalDeliveryOfficeName": null,
"homeTelephoneNumber": [],
"mobileTelephoneNumber": [],
"pagerTelephoneNumber": [],
"birthday": null,
"unixhome": "/home/Administrator",
"shell": "/bin/bash",
"sambahome": null,
"scriptpath": null,
"profilepath": null,
"homedrive": null,
"sambaRID": 500,
"groups": [
"cn=Domain Admins,cn=groups,dc=example,dc=com",
"cn=Domain Users,cn=groups,dc=example,dc=com"
],
"primaryGroup": "cn=Domain Admins,cn=groups,dc=example,dc=com",
"mailHomeServer": null,
"mailPrimaryAddress": "administrator@example.com",
"mailAlternativeAddress": [],
"mailForwardAddress": [],
"mailForwardCopyToSelf": "0",
"overridePWHistory": null,
"overridePWLength": null,
"homeShare": null,
"homeSharePath": "Administrator",
"sambaUserWorkstations": [],
"sambaLogonHours": null,
"jpegPhoto": null,
"umcProperty": {},
"univentionObjectIdentifier": null,
"univentionSourceIAM": null,
"guardianRoles": [
"guardian:builtin:super-admin"
],
"guardianInheritedRoles": [],
"PasswordRecoveryEmail": null,
"PasswordRecoveryMobile": null,
"PasswordRecoveryEmailVerified": null,
"RegisteredThroughSelfService": null,
"DeregisteredThroughSelfService": null,
"DeregistrationTimestamp": null,
"objectFlag": []
},
"options": {
"pki": false
},
"policies": {
"policies/umc": [],
"policies/pwhistory": [],
"policies/desktop": []
},
"uuid": "3c1a22f8-83e4-103f-8df6-e102f7f2195d",
"uri": "https://portal.example.com/univention/udm/users/user/uid%3DAdministrator%2Ccn%3Dusers%2Cdc%3Dexample%2Cdc%3Dcom",
"_links": {
"self": [
{
"name": "uid=Administrator,cn=users,dc=example,dc=com",
"title": "Administrator",
"href": "https://portal.example.com/univention/udm/users/user/uid%3DAdministrator%2Ccn%3Dusers%2Cdc%3Dexample%2Cdc%3Dcom"
}
]
}
}
]
},
"results": 1
2.2.6.4. Modify a user object#
This example shows the necessary steps to modify a user object. Take the following notes into account:
To modify a user object, use the following steps:
To retrieve the user object and the entity tag, run the commands in Listing 2.26. The curl command stores the headers in the
user.headers
file, and the user properties in theuser.json
file. For the initialization of the used environment variables, see Listing 2.18.$ export MODULES="users/user" $ export DN="<URL encoded string for object DN>" $ curl \ --user ${USER}:${PASSWORD} \ --request GET \ --header "Accept: application/json" \ --dump-header user.headers \ "https://${HOSTNAME}/univention/udm/${MODULE}/${DN}" \ | python3 -m json.tool > user.json
Edit the properties of the user object in the
user.json
file that you want to modify for the user object.Send the modified user object properties through a PUT request with the command in Listing 2.27.
The
user.headers
file contains the entity tag header in theetag
field. To avoid modification conflicts, the UDM HTTP REST API requires that you send the value of the entity tag header as value for theIf-Match
header.$ export MODULES="users/user" $ export DN="<URL encoded string for object DN>" $ export ETAG="<value from etag header>" $ curl \ --user ${USER}:${PASSWORD} \ --request PUT \ --header "Accept: application/json" \ --header "Content-Type: application/json" \ --header "If-Match: ${ETAG}" \ --data @user.json "https://${HOSTNAME}/univention/udm/${MODULE}/${DN}"
2.2.6.5. Delete a user object#
This example shows the steps to delete a user object through a DELETE request.
Before you can begin,
you need the user object’s distinguished name.
To ensure conditional deletion,
use the entity tag in the If-Match
header.
Take the following notes into account:
Important
You need to specify the distinguished name (DN) of an object as URL encoded string. Listing 2.17 shows an example for one way to convert the DN to a URL encoded string.
To delete a user object, use the following steps:
Optional: To retrieve the user object and the entity tag for the
If-Match
header, run the commands in Listing 2.26.To delete the object, run the commands in Listing 2.28.
$ export MODULES="users/user" $ export DN="<URL encoded string for object DN>" $ export ETAG="<value from etag header>" $ curl \ --user ${USER}:${PASSWORD} \ --request DELETE \ --header "Accept: application/json" \ --header "If-Match: $ETAG" \ "https://${HOSTNAME}/univention/udm/${MODULE}/${DN}"