---
title: "Attach security group to VM NIC"
method: POST
path: "/api/v1/vms/{id}/security-groups"
tags: ["Networking"]
---

# Attach security group to VM NIC

`POST /api/v1/vms/{id}/security-groups`

Attach a security group to a specific network interface on a VM.
The security group's rules apply to inbound and outbound traffic on that NIC.

Use `nic_id` from `GET /api/v1/vms/{id}/networks` to target a specific interface.

## Path parameters

- `id` string, uuid, required

## Headers

- `X-Project-ID` string, uuid, required

## Request body

- AttachSecurityGroupRequest
  - `security_group_id` string, uuid, required — Security group to attach.
  - `nic_id` integer, required — NIC to attach the security group to. Get from `GET /api/v1/vms/{id}/networks`.

## Response `200`

Security group attached

- SuccessResponse
  - `success` boolean
  - `message` string

## Other responses

- `400` — Invalid request parameters
- `401` — Authentication required
- `404` — Resource not found

## Changes

- **2026-05-06** `9e13a6e23934` — 1 info
  - endpoint added

[Change history](https://skmtc.dev/rafftechnologies/apis/raff-api/changes/api/v1/vms/:id/security-groups/post.md)

---

[API](https://skmtc.dev/rafftechnologies/apis/raff-api.md) · [All operations](https://skmtc.dev/rafftechnologies/apis/raff-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/rafftechnologies/raff-api/revisions/64c270db1c2e/schema)
