Skip to content

Commit e8939f6

Browse files
committed
docs: Document container temporary credentials and identity integration feature
This commit adds comprehensive documentation for the container temporary credentials feature introduced in the Container Orchestration Provider. The documentation covers: - Container Identity Integration feature in container-orchestration-provider-usage.md - Configuration parameters (Identity Integration Enabled, Container Permissions) - Detailed overview of how the feature works - Complete usage examples in Python, JavaScript, Shell Script - Best practices and troubleshooting guide - Updated container-orchestration-provider.md to list Identity Integration as a key feature - New how-to-use-temporary-identity-service.md for Java developers - TemporaryIdentityService API reference - Usage examples for OSGi bundles - Best practices and security considerations - Common use cases including container authentication - Updated authentication-and-authorization.md with new Temporary Identities section - Key characteristics of temporary identities - Differences from regular identities - API overview and usage example - Cross-references to related documentation - Updated mkdocs.yml navigation to include the new Java development guide The documentation provides developers and users with a complete understanding of how to leverage temporary credentials for secure container-to-Kura communication.
1 parent ea10303 commit e8939f6

5 files changed

Lines changed: 931 additions & 1 deletion

File tree

docs/core-services/container-orchestration-provider-usage.md

Lines changed: 295 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ To begin configuring the container, look under **Services** and select the item
9090

9191
- **Restart Container On Failure** - A boolean that tells the container engine to automatically restart the container when it has failed or shut down.
9292

93+
- **Identity Integration Enabled** - When enabled, Kura automatically creates a temporary identity with the specified permissions and provides the container with authentication credentials to access Kura's REST APIs. See [Container Identity Integration](#container-identity-integration) for more details.
94+
95+
- **Container Permissions (optional)** - A comma-separated list of permission names to grant to the container's temporary identity (e.g., `rest.system,rest.configuration`). This field is only used when **Identity Integration Enabled** is set to true. See [Container Identity Integration](#container-identity-integration) for available permissions and usage examples.
96+
9397
After specifying container parameters, ensure to set **Enabled** to **true** and press **Apply**. The container engine will then pull the respective image, spin up and start the container. If the gateway or the framework is power cycled, and the container and Container Orchestration Service are set to **enabled**, the framework will automatically start the container again upon startup.
9498

9599
![Container Orchestration Provider Container Configuration](./images/container-orchestration-provider-container-configuration.png)
@@ -141,6 +145,297 @@ The result should be a single line with all the existing options plus the new on
141145
!!! warning
142146
Modifying the bootloader options incorrectly may prevent the system from booting. Please ensure to back up any important data before making changes to these settings.
143147

148+
## Container Identity Integration
149+
150+
The Container Identity Integration feature allows containers to securely authenticate and interact with Kura's REST APIs using temporary credentials. When enabled, Kura automatically manages authentication tokens for containers, eliminating the need for manual credential configuration.
151+
152+
### Overview
153+
154+
When Identity Integration is enabled for a container instance, Kura performs the following operations:
155+
156+
1. **Creates a Temporary Identity**: A temporary, non-persistent identity is created specifically for the container with a unique name based on the container name (e.g., `container_myapp` for a container named `myapp`).
157+
158+
2. **Assigns Permissions**: The temporary identity is granted the permissions specified in the **Container Permissions** field.
159+
160+
3. **Provides Credentials**: The container receives two environment variables:
161+
- `KURA_IDENTITY_TOKEN`: The authentication token for accessing Kura's REST APIs
162+
- `KURA_REST_BASE_URL`: The complete base URL for Kura's REST API endpoints (e.g., `http://172.17.0.1:8080/services` or `https://172.17.0.1:443/services`)
163+
164+
4. **Automatic Cleanup**: When the container stops or is deleted, Kura automatically removes the temporary identity and invalidates the token.
165+
166+
### Features
167+
168+
- **Zero Configuration**: Containers automatically receive the correct REST API URL based on the gateway's HTTPS configuration and network mode.
169+
- **Network-Aware**: The REST base URL is automatically adjusted based on the container's networking mode (bridge, host, etc.).
170+
- **Secure**: Tokens are temporary and automatically invalidated when containers stop.
171+
- **Non-Persistent**: Temporary identities exist only in memory and are never persisted to disk.
172+
- **Permission-Based**: Fine-grained access control using Kura's existing permission system.
173+
174+
### Configuration
175+
176+
To enable Identity Integration for a container:
177+
178+
1. Set **Identity Integration Enabled** to `true`
179+
2. Specify the required permissions in **Container Permissions** field (comma-separated)
180+
3. Apply the configuration
181+
182+
The framework will create the temporary identity when the container starts and clean it up when the container stops.
183+
184+
### Available Permissions
185+
186+
The following permissions can be assigned to container identities. Use the exact permission names as shown below:
187+
188+
| Permission | Description |
189+
|------------|-------------|
190+
| `rest.configuration` | Access to configuration management APIs |
191+
| `rest.system` | Access to system information and management APIs |
192+
| `rest.network.configuration` | Access to network configuration APIs |
193+
| `rest.network.status` | Access to network status information |
194+
| `rest.deploy` | Access to deployment package management |
195+
| `rest.cloudconnection` | Access to cloud connection management |
196+
| `rest.assets` | Access to asset management (Wires) |
197+
| `rest.wires.admin` | Administrative access to Wires framework |
198+
| `rest.identity` | Access to identity and permission management |
199+
| `rest.security` | Access to security-related APIs |
200+
| `rest.keystores` | Access to keystore management |
201+
| `rest.command` | Access to command execution APIs |
202+
| `rest.inventory` | Access to inventory information |
203+
| `rest.position` | Access to position/GPS information |
204+
| `kura.admin` | Full administrative access (use with caution) |
205+
206+
For a complete list of available permissions, use the [REST Identity API](/references/rest-apis/rest-identity-api-v2/#get-defined-permissions) to query defined permissions in your system.
207+
208+
### Usage Examples
209+
210+
#### Example 1: Container with Read-Only System Access
211+
212+
A monitoring container that needs to read system information but cannot modify configuration:
213+
214+
**Container Configuration:**
215+
- **Identity Integration Enabled**: `true`
216+
- **Container Permissions**: `rest.system`
217+
218+
**Container Code (Python):**
219+
```python
220+
import os
221+
import requests
222+
223+
# Read credentials from environment variables
224+
token = os.environ.get('KURA_IDENTITY_TOKEN')
225+
base_url = os.environ.get('KURA_REST_BASE_URL')
226+
227+
# Make authenticated request to get system information
228+
headers = {
229+
'Authorization': f'Bearer {token}'
230+
}
231+
232+
response = requests.get(f'{base_url}/system/info', headers=headers)
233+
if response.status_code == 200:
234+
system_info = response.json()
235+
print(f"System info: {system_info}")
236+
else:
237+
print(f"Failed to get system info: {response.status_code}")
238+
```
239+
240+
#### Example 2: Container with Configuration Management Access
241+
242+
A deployment automation container that can read and update configurations:
243+
244+
**Container Configuration:**
245+
- **Identity Integration Enabled**: `true`
246+
- **Container Permissions**: `rest.configuration,rest.system`
247+
248+
**Container Code (JavaScript/Node.js):**
249+
```javascript
250+
const axios = require('axios');
251+
252+
const token = process.env.KURA_IDENTITY_TOKEN;
253+
const baseUrl = process.env.KURA_REST_BASE_URL;
254+
255+
// Configure axios with authentication header
256+
const api = axios.create({
257+
baseURL: baseUrl,
258+
headers: {
259+
'Authorization': `Bearer ${token}`
260+
}
261+
});
262+
263+
// Get current configuration
264+
async function getConfiguration(pid) {
265+
try {
266+
const response = await api.get(`/configuration/v2/configurations/${pid}`);
267+
return response.data;
268+
} catch (error) {
269+
console.error('Failed to get configuration:', error);
270+
}
271+
}
272+
273+
// Update configuration
274+
async function updateConfiguration(pid, config) {
275+
try {
276+
const response = await api.put('/configuration/v2/configurations', {
277+
pid: pid,
278+
properties: config
279+
});
280+
return response.data;
281+
} catch (error) {
282+
console.error('Failed to update configuration:', error);
283+
}
284+
}
285+
286+
// Example usage
287+
(async () => {
288+
const config = await getConfiguration('org.eclipse.kura.clock.ClockService');
289+
console.log('Current clock config:', config);
290+
291+
// Modify and update configuration
292+
config.properties['clock.ntp.enabled'] = true;
293+
await updateConfiguration('org.eclipse.kura.clock.ClockService', config.properties);
294+
})();
295+
```
296+
297+
#### Example 3: Container with Network Management Access
298+
299+
A network diagnostic container that monitors network status:
300+
301+
**Container Configuration:**
302+
- **Identity Integration Enabled**: `true`
303+
- **Container Permissions**: `rest.network.status,rest.network.configuration`
304+
305+
**Container Code (Shell Script):**
306+
```bash
307+
#!/bin/bash
308+
309+
# Read credentials from environment
310+
TOKEN="${KURA_IDENTITY_TOKEN}"
311+
BASE_URL="${KURA_REST_BASE_URL}"
312+
313+
# Function to make authenticated API calls
314+
kura_api() {
315+
curl -s -H "Authorization: Bearer ${TOKEN}" "${BASE_URL}$1"
316+
}
317+
318+
# Get network interfaces status
319+
echo "Fetching network interfaces..."
320+
kura_api "/network/v2/interfaces" | jq '.'
321+
322+
# Get modem status
323+
echo "Fetching modem status..."
324+
kura_api "/network/v2/modems" | jq '.'
325+
```
326+
327+
#### Example 4: Multi-Permission Container for Data Collection
328+
329+
A telemetry container that collects various system metrics:
330+
331+
**Container Configuration:**
332+
- **Identity Integration Enabled**: `true`
333+
- **Container Permissions**: `rest.system,rest.network.status,rest.position,rest.inventory`
334+
335+
**Container Code (Python):**
336+
```python
337+
import os
338+
import requests
339+
import time
340+
import json
341+
342+
class KuraClient:
343+
def __init__(self):
344+
self.token = os.environ.get('KURA_IDENTITY_TOKEN')
345+
self.base_url = os.environ.get('KURA_REST_BASE_URL')
346+
self.headers = {
347+
'Authorization': f'Bearer {self.token}',
348+
'Content-Type': 'application/json'
349+
}
350+
351+
def get(self, endpoint):
352+
"""Make authenticated GET request to Kura API"""
353+
url = f'{self.base_url}{endpoint}'
354+
response = requests.get(url, headers=self.headers)
355+
response.raise_for_status()
356+
return response.json()
357+
358+
def collect_telemetry(self):
359+
"""Collect telemetry data from various Kura APIs"""
360+
telemetry = {}
361+
362+
try:
363+
# Collect system information
364+
telemetry['system'] = self.get('/system/info')
365+
except Exception as e:
366+
telemetry['system'] = {'error': str(e)}
367+
368+
try:
369+
# Collect network status
370+
telemetry['network'] = self.get('/network/v2/interfaces')
371+
except Exception as e:
372+
telemetry['network'] = {'error': str(e)}
373+
374+
try:
375+
# Collect position data
376+
telemetry['position'] = self.get('/position/v1/current')
377+
except Exception as e:
378+
telemetry['position'] = {'error': str(e)}
379+
380+
try:
381+
# Collect inventory
382+
telemetry['inventory'] = self.get('/inventory/v1/devices')
383+
except Exception as e:
384+
telemetry['inventory'] = {'error': str(e)}
385+
386+
return telemetry
387+
388+
# Main telemetry loop
389+
client = KuraClient()
390+
391+
while True:
392+
try:
393+
data = client.collect_telemetry()
394+
print(json.dumps(data, indent=2))
395+
396+
# Send to external monitoring system or process locally
397+
# ...
398+
399+
time.sleep(60) # Collect every minute
400+
except Exception as e:
401+
print(f"Error collecting telemetry: {e}")
402+
time.sleep(60)
403+
```
404+
405+
### Best Practices
406+
407+
1. **Principle of Least Privilege**: Only grant permissions that are absolutely necessary for the container's functionality.
408+
409+
2. **Validate Environment Variables**: Always check that `KURA_IDENTITY_TOKEN` and `KURA_REST_BASE_URL` are present before making API calls.
410+
411+
3. **Handle Token Lifecycle**: Be prepared for the token to become invalid when the container is stopping or restarting.
412+
413+
4. **Error Handling**: Implement proper error handling for API calls, as permissions may be denied if the container doesn't have the required permission.
414+
415+
5. **Network Mode Considerations**: The REST base URL is automatically adjusted based on network mode:
416+
- **bridge mode** (default): Uses the Docker bridge gateway IP (typically `172.17.0.1`)
417+
- **host mode**: Uses `localhost`
418+
419+
6. **HTTPS Support**: The REST base URL automatically uses HTTPS if enabled in Kura's HTTP Service configuration.
420+
421+
### Troubleshooting
422+
423+
**Container cannot access Kura APIs:**
424+
- Verify that **Identity Integration Enabled** is set to `true`
425+
- Check that the container has been granted the necessary permissions in **Container Permissions**
426+
- Ensure the container is reading the environment variables correctly
427+
- Check container logs for authentication errors
428+
429+
**Token authentication fails:**
430+
- Verify the token is being sent in the `Authorization` header as `Bearer <token>`
431+
- Check that the temporary identity was created successfully in Kura logs
432+
- Ensure the container is using the correct REST base URL
433+
434+
**Permission denied errors:**
435+
- Verify the permission name is correct (case-sensitive)
436+
- Ensure the permission exists in the system (use the REST Identity API to list defined permissions)
437+
- Check that the permission was correctly added to the **Container Permissions** field
438+
144439
## Stopping the container
145440
146441
!!! warning

docs/core-services/container-orchestration-provider.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22

33
The Container Orchestration Provider allows Kura to manage Docker. With this tool, you can arbitrarily pull and deploy containerized software packages and run them on your gateway. This Service allows the user to create, configure, start, and stop containers all from the browser. The bundle will also restart containers if the gateway is restarted.
44

5-
The feature is composed of two bundles, one that exposes APIs for container management and one that implements those APIs. This API is exposed so that you can leverage it to implement containerization in your own Kura plugins.
5+
The feature is composed of two bundles, one that exposes APIs for container management and one that implements those APIs. This API is exposed so that you can leverage it to implement containerization in your own Kura plugins.
6+
7+
## Key Features
8+
9+
- **Container Lifecycle Management**: Create, start, stop, and manage Docker containers through Kura's web interface
10+
- **Image Management**: Pull images from Docker Hub or authenticated registries with automatic retry and timeout configuration
11+
- **Resource Control**: Configure CPU, memory, GPU allocation, and cgroup settings for containers
12+
- **Network Configuration**: Support for various Docker networking modes (bridge, host, custom networks)
13+
- **Security**: Container image signature verification and allowlist enforcement
14+
- **Identity Integration**: Automatic provisioning of temporary credentials for containers to securely access Kura's REST APIs
15+
- **Persistence**: Automatic container restart after gateway reboot if configured

0 commit comments

Comments
 (0)