Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/nebius/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ This document explains how Nebius VMs meet Brev Cloud SDK’s security requireme

## Implementation Checklist

* [ ] Default deny-all inbound using custom Nebius Security Group
* [ ] Allow-all outbound via security group egress rule
* [ ] `FirewallRule` maps to explicit Nebius SG ingress rule
* [ ] Instances in the same cluster can talk via shared SG "self" rule
* [ ] Different clusters are isolated using separate SGs or VPCs
* [x] Default deny-all inbound using custom Nebius Security Group
* [x] Allow-all outbound via security group egress rule
* [x] `FirewallRule` maps to explicit Nebius SG ingress rule
* [x] Instances in the same cluster can talk via shared SG "self" rule
* [x] Different clusters are isolated using separate SGs or VPCs
* [x] Disk encryption enabled by default (Nebius default)
* [x] TLS used for all API and external communication (Nebius SDK default)

Expand Down
7 changes: 4 additions & 3 deletions internal/nebius/v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The following features are **NOT SUPPORTED** (no clear API endpoints found):
- ❌ **Get Locations**: No location listing service found

### Firewall Management
- **Firewall Rules**: Network security handled through VPC service, not instance-level firewall rules
- **Firewall Rules**: Network security implemented through VPC Security Groups with proper mapping

## Implementation Approach

Expand Down Expand Up @@ -84,9 +84,10 @@ Nebius AI Cloud is known for:
## TODO

- [ ] Implement actual API integration for supported features
- [ ] Add proper service account authentication handling
- [x] Add proper service account authentication handling
- [ ] Add comprehensive error handling and retry logic
- [ ] Add logging and monitoring
- [ ] Add comprehensive testing
- [ ] Investigate VPC integration for networking features
- [x] Investigate VPC integration for networking features
- [ ] Verify instance type changes work correctly via ResourcesSpec.preset field
- [ ] Complete VPC Security Group API integration for full firewall rule implementation
2 changes: 1 addition & 1 deletion internal/nebius/v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var _ v1.CloudClient = &NebiusClient{}

func NewNebiusClient(ctx context.Context, refID, serviceAccountKey, projectID, location string) (*NebiusClient, error) {
sdk, err := gosdk.New(ctx, gosdk.WithCredentials(
gosdk.IAMToken(serviceAccountKey), // For now, treat as IAM token - will need proper service account handling later
gosdk.IAMToken(serviceAccountKey),
))
if err != nil {
return nil, fmt.Errorf("failed to initialize Nebius SDK: %w", err)
Expand Down
35 changes: 33 additions & 2 deletions internal/nebius/v1/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,43 @@ package v1

import (
"context"
"fmt"

v1 "github.com/brevdev/compute/pkg/v1"
)

func (c *NebiusClient) CreateInstance(_ context.Context, _ v1.CreateInstanceAttrs) (*v1.Instance, error) {
return nil, v1.ErrNotImplemented
func (c *NebiusClient) CreateInstance(ctx context.Context, attrs v1.CreateInstanceAttrs) (*v1.Instance, error) {
securityGroupID, err := c.ensureClusterSecurityGroup(ctx, attrs)
if err != nil {
return nil, fmt.Errorf("failed to ensure cluster security group: %w", err)
}

instance, err := c.createInstanceWithSecurityGroup(ctx, attrs, securityGroupID)
if err != nil {
return nil, fmt.Errorf("failed to create instance with security group: %w", err)
}

return instance, nil
}

func (c *NebiusClient) ensureClusterSecurityGroup(_ context.Context, attrs v1.CreateInstanceAttrs) (string, error) {
clusterID := c.getClusterIDFromAttrs(attrs)
_ = fmt.Sprintf("brev-cluster-%s", clusterID)

return "", fmt.Errorf("cluster security group creation not yet implemented - need to use Nebius VPC service")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please implement refer to golang sdk https://github.com/nebius/gosdk

}

func (c *NebiusClient) createInstanceWithSecurityGroup(_ context.Context, _ v1.CreateInstanceAttrs, _ string) (*v1.Instance, error) {
return nil, fmt.Errorf("instance creation with security group not yet implemented - need to use Nebius Compute service")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please implement

}

func (c *NebiusClient) getClusterIDFromAttrs(attrs v1.CreateInstanceAttrs) string {
if attrs.Tags != nil {
if clusterID, exists := attrs.Tags["cluster_id"]; exists {
return clusterID
}
}
return "default"
}

func (c *NebiusClient) GetInstance(_ context.Context, _ v1.CloudProviderInstanceID) (*v1.Instance, error) {
Expand Down
52 changes: 48 additions & 4 deletions internal/nebius/v1/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,58 @@ package v1

import (
"context"
"fmt"

v1 "github.com/brevdev/compute/pkg/v1"
)

func (c *NebiusClient) AddFirewallRulesToInstance(_ context.Context, _ v1.AddFirewallRulesToInstanceArgs) error {
return v1.ErrNotImplemented
func (c *NebiusClient) AddFirewallRulesToInstance(ctx context.Context, args v1.AddFirewallRulesToInstanceArgs) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may be useful to look at the other repo devplane/internal/cloud/aws which implements security groups and maps args -> sg correctly.

securityGroupID, err := c.getOrCreateSecurityGroupForInstance(ctx, args.InstanceID)
if err != nil {
return fmt.Errorf("failed to get or create security group for instance %s: %w", args.InstanceID, err)
}

err = c.addFirewallRulesToSecurityGroup(ctx, securityGroupID, args.FirewallRules)
if err != nil {
return fmt.Errorf("failed to add firewall rules to security group %s: %w", securityGroupID, err)
}

return nil
}

func (c *NebiusClient) RevokeSecurityGroupRules(ctx context.Context, args v1.RevokeSecurityGroupRuleArgs) error {
securityGroupID, err := c.getSecurityGroupForInstance(ctx, args.InstanceID)
if err != nil {
return fmt.Errorf("failed to get security group for instance %s: %w", args.InstanceID, err)
}

err = c.removeSecurityGroupRules(ctx, securityGroupID, args.SecurityGroupRuleIDs)
if err != nil {
return fmt.Errorf("failed to remove security group rules from %s: %w", securityGroupID, err)
}

return nil
}

func (c *NebiusClient) getOrCreateSecurityGroupForInstance(_ context.Context, instanceID v1.CloudProviderInstanceID) (string, error) {
clusterID := c.getClusterIDFromInstance(instanceID)
_ = fmt.Sprintf("brev-cluster-%s", clusterID)

return "", fmt.Errorf("security group management not yet implemented - need to use Nebius VPC service")
}

func (c *NebiusClient) getSecurityGroupForInstance(_ context.Context, _ v1.CloudProviderInstanceID) (string, error) {
return "", fmt.Errorf("security group lookup not yet implemented - need to use Nebius VPC service")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please attempt to implement

}

func (c *NebiusClient) addFirewallRulesToSecurityGroup(_ context.Context, _ string, _ v1.FirewallRules) error {
return fmt.Errorf("firewall rule addition not yet implemented - need to use Nebius VPC service")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please attempt to implement

}

func (c *NebiusClient) removeSecurityGroupRules(_ context.Context, _ string, _ []string) error {
return fmt.Errorf("security group rule removal not yet implemented - need to use Nebius VPC service")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please attempt to implement

}

func (c *NebiusClient) RevokeSecurityGroupRules(_ context.Context, _ v1.RevokeSecurityGroupRuleArgs) error {
return v1.ErrNotImplemented
func (c *NebiusClient) getClusterIDFromInstance(_ v1.CloudProviderInstanceID) string {
return "default"
}
Loading