### Auto-install NVIDIA Drivers using ubuntu-drivers Source: https://brokkr.hydrahost.com/docs/nvidia-smi-not-working Installs the latest NVIDIA drivers on an Ubuntu system. This command is useful for resolving issues where the 'nvidia-smi' command is not working due to missing or incorrect driver installations. It requires root privileges. ```bash sudo ubuntu-drivers autoinstall ``` -------------------------------- ### Verify Webhook Signature with Python Source: https://brokkr.hydrahost.com/docs/brokkr-api-webhooks Verifies the HMAC-SHA256 signature of a webhook request using Python's hmac and hashlib modules. It computes the expected signature using the webhook secret and compares it with the signature from the 'X-Webhook-Signature' header using hmac.compare_digest for security. The example demonstrates integration with Flask. ```python import hmac import hashlib def verify_webhook_signature(body: bytes, signature: str, secret: str) -> bool: expected_signature = 'sha256=' + hmac.new( secret.encode('utf-8'), body, hashlib.sha256 ).hexdigest() return hmac.compare_digest(signature, expected_signature) # Flask example from flask import Flask, request, abort app = Flask(__name__) @app.route('/webhook', methods=['POST']) def handle_webhook(): signature = request.headers.get('X-Webhook-Signature') body = request.get_data() if not verify_webhook_signature(body, signature, os.environ['WEBHOOK_SECRET']): abort(401) event = request.get_json() print(f"Received event: {event['eventType']}") return 'OK', 200 ``` -------------------------------- ### Verify Webhook Signature with Go Source: https://brokkr.hydrahost.com/docs/brokkr-api-webhooks Verifies the HMAC-SHA256 signature of a webhook request using Go's crypto/hmac and crypto/sha256 packages. It calculates the expected signature from the request body and the secret, then compares it with the 'X-Webhook-Signature' header using hmac.Equal for secure comparison. The example shows a standard http.Handler function. ```go package main import ( "crypto/hmac" "crypto/sha256" "encoding/hex" "fmt" "io" "net/http" ) func verifyWebhookSignature(body []byte, signature, secret string) bool { h := hmac.New(sha256.New, []byte(secret)) h.Write(body) expectedSignature := "sha256=" + hex.EncodeToString(h.Sum(nil)) return hmac.Equal([]byte(signature), []byte(expectedSignature)) } func webhookHandler(w http.ResponseWriter, r *http.Request) { signature := r.Header.Get("X-Webhook-Signature") body, err := io.ReadAll(r.Body) if err != nil { http.Error(w, "Failed to read body", http.StatusBadRequest) return } if !verifyWebhookSignature(body, signature, os.Getenv("WEBHOOK_SECRET")) { http.Error(w, "Invalid signature", http.StatusUnauthorized) return } // Process the webhook fmt.Println("Webhook verified and received") w.WriteHeader(http.StatusOK) } ``` -------------------------------- ### Configure NVIDIA Driver and CUDA Toolkit Environment Variables Source: https://brokkr.hydrahost.com/docs/nvidia-driver-and-cuda-toolkit Sets essential environment variables for NVIDIA driver and CUDA toolkit functionality. The PATH variable is updated to include CUDA binaries, and LD_LIBRARY_PATH is set for CUDA libraries. These are typically applied automatically from /etc/environment. ```shell export PATH="/usr/local/cuda-12.2/bin:$PATH" export LD_LIBRARY_PATH="/usr/local/cuda-12.2/lib64:$LD_LIBRARY_PATH" ``` -------------------------------- ### List SSH Keys in Agent Source: https://brokkr.hydrahost.com/docs/ssh-keys-with-brokkr Command to list all public SSH keys currently managed by the SSH agent. This helps verify if your SSH key is recognized by the agent and accessible for use. ```bash ssh-add -L ``` -------------------------------- ### Add SSH Private Key to Agent Source: https://brokkr.hydrahost.com/docs/ssh-keys-with-brokkr Command to add your private SSH key to the SSH agent. This makes the key available for authentication when connecting to servers. Replace `~/.ssh/nameofprivatekey` with the actual path to your private key file. ```bash ssh-add ~/.ssh/nameofprivatekey ``` -------------------------------- ### Generate SSH Key Pair Source: https://brokkr.hydrahost.com/docs/ssh-keys-with-brokkr Command to generate a new SSH key pair (public and private). This is useful when you need to create a new SSH key to associate with your Brokkr account for server access. It prompts for a key name and passphrase. ```bash ssh-keygen -t rsa -b 2048 ``` -------------------------------- ### Webhooks Source: https://brokkr.hydrahost.com/docs/brokkr-api-webhooks Webhooks allow you to receive real-time HTTP POST notifications when events occur in your Brokkr organization. Instead of polling the API for changes, webhooks push data to your endpoint as events happen. ```APIDOC ## POST /webhooks ### Description Receives real-time HTTP POST notifications for events occurring within your Brokkr organization. ### Method POST ### Endpoint /webhooks ### Parameters #### Headers - **X-Webhook-Signature** (string) - Required - HMAC-SHA256 signature for request verification. - **X-Webhook-Event** (string) - Required - The event type (e.g., DEVICE_LISTING_CREATED). - **X-Webhook-Delivery** (string) - Required - Unique ID for this delivery attempt. - **X-Webhook-Timestamp** (string) - Required - ISO 8601 timestamp of when the webhook was sent. - **User-Agent** (string) - Always set to "Brokkr-Webhooks/1.0". #### Request Body - **data** (object) - Required - Event-specific data. - **id** (string) - Device UUID. - **name** (string) - Device name. - **status** (string) - Device status. - *additional fields* - **eventType** (string) - Required - The type of event that occurred. - **timestamp** (string) - Required - ISO 8601 timestamp of the event. ### Request Example ```json { "data": { "id": "device-uuid", "name": "NVIDIA RTX 4090", "status": "on demand" }, "eventType": "DEVICE_LISTING_CREATED", "timestamp": "2021-01-01T00:00:00.000Z" } ``` ### Response #### Success Response (200) - **Status** (string) - Indicates successful receipt of the webhook. #### Response Example ```json "OK" ``` ### Signature Verification To ensure webhook requests are authentic, verify the `X-Webhook-Signature` header using the provided secret. #### Verification Steps 1. Extract the signature from the `X-Webhook-Signature` header. 2. Compute an HMAC-SHA256 hash of the raw request body using your webhook secret. 3. Compare your computed signature with the received signature. #### Example Implementation (Node.js / JavaScript) ```javascript const crypto = require('crypto'); function verifyWebhookSignature(body, signature, secret) { const expectedSignature = 'sha256=' + crypto.createHmac('sha256', secret) .update(body, 'utf8') .digest('hex'); return crypto.timingSafeEqual( Buffer.from(signature), Buffer.from(expectedSignature) ); } // Express.js example app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => { const signature = req.headers['x-webhook-signature']; const isValid = verifyWebhookSignature(req.body, signature, process.env.WEBHOOK_SECRET); if (!isValid) { return res.status(401).send('Invalid signature'); } const event = JSON.parse(req.body); console.log('Received event:', event.eventType); res.status(200).send('OK'); }); ``` #### Example Implementation (Python) ```python import hmac import hashlib import os from flask import Flask, request, abort def verify_webhook_signature(body: bytes, signature: str, secret: str) -> bool: expected_signature = 'sha256=' + hmac.new( secret.encode('utf-8'), body, hashlib.sha256 ).hexdigest() return hmac.compare_digest(signature, expected_signature) app = Flask(__name__) @app.route('/webhook', methods=['POST']) def handle_webhook(): signature = request.headers.get('X-Webhook-Signature') body = request.get_data() if not verify_webhook_signature(body, signature, os.environ['WEBHOOK_SECRET']): abort(401) event = request.get_json() print(f"Received event: {event['eventType']}") return 'OK', 200 ``` #### Example Implementation (Go) ```go package main import ( "crypto/hmac" "crypto/sha256" "encoding/hex" "fmt" "io" "net/http" "os" ) func verifyWebhookSignature(body []byte, signature, secret string) bool { h := hmac.New(sha256.New, []byte(secret)) h.Write(body) expectedSignature := "sha256=" + hex.EncodeToString(h.Sum(nil)) return hmac.Equal([]byte(signature), []byte(expectedSignature)) } func webhookHandler(w http.ResponseWriter, r *http.Request) { signature := r.Header.Get("X-Webhook-Signature") body, err := io.ReadAll(r.Body) if err != nil { http.Error(w, "Failed to read body", http.StatusBadRequest) return } if !verifyWebhookSignature(body, signature, os.Getenv("WEBHOOK_SECRET")) { http.Error(w, "Invalid signature", http.StatusUnauthorized) return } fmt.Println("Webhook verified and received") w.WriteHeader(http.StatusOK) } ``` ``` -------------------------------- ### Authenticate Brokkr API Requests with API Key Source: https://brokkr.hydrahost.com/docs/brokkr-api-authentication To authenticate any requests made to the Brokkr API, you must include your API key in the request header. This is a standard method for securing API access. ```http X-API-KEY: your_api_key_here ``` -------------------------------- ### Verify Webhook Signature with Node.js Source: https://brokkr.hydrahost.com/docs/brokkr-api-webhooks Verifies the HMAC-SHA256 signature of a webhook request using Node.js's crypto module. It compares the computed signature with the one provided in the 'X-Webhook-Signature' header to ensure authenticity. This implementation uses timingSafeEqual for security against timing attacks. ```javascript const crypto = require('crypto'); function verifyWebhookSignature(body, signature, secret) { const expectedSignature = 'sha256=' + crypto.createHmac('sha256', secret) .update(body, 'utf8') .digest('hex'); // Use timingSafeEqual to prevent timing attacks return crypto.timingSafeEqual( Buffer.from(signature), Buffer.from(expectedSignature) ); } // Express.js example app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => { const signature = req.headers['x-webhook-signature']; const isValid = verifyWebhookSignature(req.body, signature, process.env.WEBHOOK_SECRET); if (!isValid) { return res.status(401).send('Invalid signature'); } const event = JSON.parse(req.body); // Process the webhook event console.log('Received event:', event.eventType); res.status(200).send('OK'); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.