> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aion.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Update a Security Groups

> Updates a security group's name, description, metadata, and/or rules.

When updating rules:
- Rules with `external_id` will be updated
- Rules without `external_id` will be created as new rules
- Existing rules not included in the request will remain unchanged




## OpenAPI

````yaml PUT /api/v1/accounts/{accountId}/projects/{projectId}/security-groups/{securityGroupId}
openapi: 3.0.3
info:
  title: AION Firewall (Security Groups) API
  description: >
    API for managing firewall security groups and rules in AION Cloud Platform.


    Security groups act as virtual firewalls that control inbound and outbound
    traffic 

    for resources within a project.
  version: 1.0.0
  contact:
    name: AION Platform Team
    email: platform@aion.xyz
servers:
  - url: https://api.aion.xyz
    description: Production
  - url: https://api.staging.aion.xyz
    description: Staging
  - url: http://localhost:8080
    description: Local Development
security:
  - BearerAuth: []
tags:
  - name: Security Groups
    description: Firewall security group management
paths:
  /api/v1/accounts/{accountId}/projects/{projectId}/security-groups/{securityGroupId}:
    put:
      tags:
        - Security Groups
      summary: Update a security group
      description: |
        Updates a security group's name, description, metadata, and/or rules.

        When updating rules:
        - Rules with `external_id` will be updated
        - Rules without `external_id` will be created as new rules
        - Existing rules not included in the request will remain unchanged
      operationId: updateSecurityGroup
      parameters:
        - $ref: '#/components/parameters/AccountId'
        - $ref: '#/components/parameters/ProjectId'
        - $ref: '#/components/parameters/SecurityGroupId'
        - $ref: '#/components/parameters/XAccountId'
        - $ref: '#/components/parameters/XUserId'
        - $ref: '#/components/parameters/XRequestId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateSecurityGroupRequest'
            example:
              name: web-servers-sg-updated
              description: Updated security group for web servers
              rules:
                - external_id: sgr-existing123-v1
                  direction: ingress
                  protocol: tcp
                  port_range_min: 8080
                  port_range_max: 8080
                  remote_ip_prefix: 0.0.0.0/0
                  description: 'Updated: Allow traffic on port 8080'
                - direction: ingress
                  protocol: tcp
                  port_range_min: 3000
                  port_range_max: 3000
                  remote_ip_prefix: 10.0.0.0/8
                  description: 'New rule: Allow internal API traffic'
      responses:
        '200':
          description: Security group updated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UpdateSecurityGroupResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  parameters:
    AccountId:
      name: accountId
      in: path
      required: true
      description: Account external ID
      schema:
        type: string
        pattern: ^acct-[a-zA-Z0-9]+-v1$
      example: acct-abc123xyz-v1
    ProjectId:
      name: projectId
      in: path
      required: true
      description: Project external ID
      schema:
        type: string
        pattern: ^proj-[a-zA-Z0-9]+-v1$
      example: proj-def456uvw-v1
    SecurityGroupId:
      name: securityGroupId
      in: path
      required: true
      description: Security group external ID
      schema:
        type: string
        pattern: ^sg-[a-zA-Z0-9]+-v1$
      example: sg-ghi789rst-v1
    XAccountId:
      name: x-account-id
      in: header
      description: Account ID from authentication (must match path accountId)
      schema:
        type: string
    XUserId:
      name: x-user-id
      in: header
      description: User ID performing the action
      schema:
        type: string
    XRequestId:
      name: X-Request-ID
      in: header
      description: Unique request ID for tracing
      schema:
        type: string
  schemas:
    UpdateSecurityGroupRequest:
      type: object
      properties:
        name:
          type: string
          description: Updated security group name
          minLength: 1
          maxLength: 255
        description:
          type: string
          description: Updated description
        rules:
          type: array
          description: Rules to create or update
          items:
            $ref: '#/components/schemas/SecurityGroupRuleUpdateInput'
        metadata:
          type: object
          description: Updated metadata
          additionalProperties: true
    UpdateSecurityGroupResponse:
      type: object
      properties:
        security_group:
          $ref: '#/components/schemas/SecurityGroup'
        message:
          type: string
          example: Security group updated successfully
    SecurityGroupRuleUpdateInput:
      allOf:
        - $ref: '#/components/schemas/SecurityGroupRuleInput'
        - type: object
          properties:
            external_id:
              type: string
              description: External ID of existing rule to update (omit for new rules)
              example: sgr-abc123-v1
    SecurityGroup:
      type: object
      properties:
        id:
          type: string
          description: Security group external ID
          example: sg-abc123xyz-v1
        account_id:
          type: string
          description: Account external ID
        project_id:
          type: string
          description: Project external ID
        name:
          type: string
          description: Security group name
        description:
          type: string
        status:
          type: string
          enum:
            - active
            - pending
            - error
            - deleting
            - deleted
        metadata:
          type: object
          additionalProperties: true
        rules:
          type: array
          items:
            $ref: '#/components/schemas/SecurityGroupRule'
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        is_deleted:
          type: boolean
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
          description: Error message
        code:
          type: string
          description: Error code
        details:
          type: object
          description: Additional error details
    SecurityGroupRuleInput:
      type: object
      required:
        - direction
        - protocol
      properties:
        direction:
          type: string
          enum:
            - ingress
            - egress
          description: Traffic direction
        protocol:
          type: string
          description: Protocol (tcp, udp, icmp, or protocol number)
          example: tcp
        port_range_min:
          type: integer
          minimum: 0
          maximum: 65535
          description: Start of port range
        port_range_max:
          type: integer
          minimum: 0
          maximum: 65535
          description: End of port range
        remote_ip_prefix:
          type: string
          description: CIDR notation for allowed IP range
          example: 0.0.0.0/0
        remote_security_group_id:
          type: string
          description: Allow traffic from another security group
          example: sg-other123-v1
        icmp_type:
          type: integer
          description: ICMP type (for ICMP protocol)
        icmp_code:
          type: integer
          description: ICMP code (for ICMP protocol)
        priority:
          type: integer
          description: Rule priority (lower = higher priority)
          default: 100
        description:
          type: string
          description: Rule description
    SecurityGroupRule:
      type: object
      properties:
        id:
          type: string
          description: Rule external ID
          example: sgr-abc123xyz-v1
        security_group_id:
          type: string
          description: Parent security group ID
        direction:
          type: string
          enum:
            - ingress
            - egress
        protocol:
          type: string
        port_range_min:
          type: integer
        port_range_max:
          type: integer
        remote_ip_prefix:
          type: string
        remote_security_group_id:
          type: string
        icmp_type:
          type: integer
        icmp_code:
          type: integer
        priority:
          type: integer
        description:
          type: string
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        is_deleted:
          type: boolean
  responses:
    BadRequest:
      description: Bad request - Invalid input parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: 'Validation failed: name is required'
            code: BAD_REQUEST
    Unauthorized:
      description: Unauthorized - Authentication required or account mismatch
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: account_id mismatch between header and path
            code: UNAUTHORIZED
    NotFound:
      description: Not found - Resource does not exist
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: Security group not found
            code: NOT_FOUND
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error: Internal server error
            code: INTERNAL_ERROR
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT token from authentication service

````