安全配置 #

一、安全概述 #

1.1 Neptune安全层次 #

text
安全层次:
├── 网络安全
│   ├── VPC隔离
│   ├── 安全组
│   └── 网络ACL
├── 访问控制
│   ├── IAM认证
│   └── 资源策略
├── 数据安全
│   ├── 传输加密
│   └── 静态加密
└── 审计日志
    └── CloudWatch Logs

二、网络隔离 #

2.1 VPC配置 #

text
VPC配置建议:
├── 使用私有子网
├── 配置NAT网关(如需公网访问)
├── 使用VPC端点
└── 禁止公网访问

2.2 安全组配置 #

bash
# 创建安全组
aws ec2 create-security-group \
  --group-name neptune-sg \
  --description "Neptune security group" \
  --vpc-id vpc-xxx

# 配置入站规则
aws ec2 authorize-security-group-ingress \
  --group-id sg-xxx \
  --protocol tcp \
  --port 8182 \
  --source-group sg-yyy  # 应用服务器安全组

# 配置出站规则
aws ec2 authorize-security-group-egress \
  --group-id sg-xxx \
  --protocol tcp \
  --port 8182 \
  --cidr 0.0.0.0/0

2.3 网络ACL #

text
网络ACL建议:
├── 限制入站流量
├── 限制出站流量
├── 使用最小权限原则
└── 记录日志

三、IAM认证 #

3.1 启用IAM认证 #

bash
# 启用IAM数据库认证
aws neptune modify-db-cluster \
  --db-cluster-identifier my-neptune-cluster \
  --enable-iam-database-authentication \
  --apply-immediately

3.2 IAM策略配置 #

json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "neptune-db:connect"
      ],
      "Resource": [
        "arn:aws:neptune-db:region:account:cluster-identifier"
      ]
    }
  ]
}

3.3 IAM角色配置 #

json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "neptune-db:connect",
        "neptune-db:ReadDataViaQuery",
        "neptune-db:WriteDataViaQuery"
      ],
      "Resource": [
        "arn:aws:neptune-db:region:account:cluster-identifier"
      ]
    }
  ]
}

3.4 使用IAM认证连接 #

python
import requests
from requests_aws4auth import AWS4Auth
import boto3

# 获取凭证
credentials = boto3.Session().get_credentials()
auth = AWS4Auth(
    credentials.access_key,
    credentials.secret_key,
    'us-east-1',
    'neptune-db',
    session_token=credentials.token
)

# 发送请求
endpoint = 'https://your-cluster-endpoint:8182/gremlin'
response = requests.post(endpoint, auth=auth, json={'gremlin': 'g.V().limit(10)'})

四、数据加密 #

4.1 静态加密 #

bash
# 创建加密集群
aws neptune create-db-cluster \
  --db-cluster-identifier my-neptune-cluster \
  --engine neptune \
  --storage-encrypted \
  --kms-key-id alias/aws/neptune

4.2 传输加密 #

text
传输加密特点:
├── 默认启用TLS
├── 强制HTTPS连接
├── 支持TLS 1.2
└── 证书验证

4.3 KMS密钥管理 #

bash
# 创建KMS密钥
aws kms create-key \
  --description "Neptune encryption key" \
  --policy '{
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Principal": {"AWS": "arn:aws:iam::account:root"},
        "Action": "kms:*",
        "Resource": "*"
      }
    ]
  }'

# 创建别名
aws kms create-alias \
  --alias-name alias/neptune-key \
  --target-key-id key-id

五、访问控制 #

5.1 资源策略 #

json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::account:role/NeptuneAccessRole"
      },
      "Action": [
        "neptune-db:connect",
        "neptune-db:ReadDataViaQuery",
        "neptune-db:WriteDataViaQuery",
        "neptune-db:DeleteDataViaQuery"
      ],
      "Resource": "arn:aws:neptune-db:region:account:cluster-identifier"
    }
  ]
}

5.2 条件访问 #

json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": ["neptune-db:connect"],
      "Resource": ["*"],
      "Condition": {
        "IpAddress": {
          "aws:SourceIp": ["10.0.0.0/8"]
        }
      }
    }
  ]
}

六、审计日志 #

6.1 启用审计日志 #

bash
# 启用CloudWatch日志
aws neptune modify-db-cluster \
  --db-cluster-identifier my-neptune-cluster \
  --cloudwatch-logs-export-configuration '{"EnableLogTypes":["audit"]}'

6.2 日志内容 #

text
审计日志内容:
├── 连接事件
├── 查询事件
├── 数据修改
├── 权限变更
└── 错误事件

6.3 日志分析 #

bash
# 查询CloudWatch日志
aws logs filter-log-events \
  --log-group-name /aws/neptune/my-cluster/audit \
  --start-time $(date -d '1 hour ago' +%s)000

七、安全最佳实践 #

7.1 网络安全 #

text
网络安全建议:
├── 使用私有子网
├── 配置安全组限制访问
├── 禁止公网访问
├── 使用VPC端点
└── 监控网络流量

7.2 访问控制 #

text
访问控制建议:
├── 启用IAM认证
├── 使用最小权限原则
├── 定期轮换凭证
├── 监控访问日志
└── 实施MFA

7.3 数据安全 #

text
数据安全建议:
├── 启用静态加密
├── 使用客户管理密钥
├── 启用传输加密
├── 定期备份
└── 监控数据访问

八、合规认证 #

8.1 Neptune合规认证 #

text
合规认证:
├── SOC 1/2/3
├── PCI DSS
├── HIPAA
├── ISO 27001
├── ISO 27017
├── ISO 27018
└── FedRAMP

8.2 合规配置 #

text
合规配置建议:
├── 启用所有安全功能
├── 配置审计日志
├── 实施访问控制
├── 定期安全审计
└── 保留审计记录

九、安全监控 #

9.1 CloudWatch告警 #

bash
# 创建安全告警
aws cloudwatch put-metric-alarm \
  --alarm-name neptune-auth-failures \
  --metric-name AuthFailures \
  --namespace AWS/Neptune \
  --threshold 10 \
  --comparison-operator GreaterThanThreshold \
  --evaluation-periods 1

9.2 GuardDuty集成 #

text
GuardDuty检测:
├── 异常访问模式
├── 潜在的攻击行为
├── 数据泄露风险
└── 权限滥用

十、总结 #

安全配置要点:

项目 说明
网络隔离 VPC、安全组
IAM认证 基于角色的访问
数据加密 静态和传输加密
审计日志 访问和操作日志
合规认证 多项合规标准

最佳实践:

  1. 使用私有网络部署
  2. 启用IAM认证
  3. 启用数据加密
  4. 配置审计日志
  5. 定期安全审计

下一步,让我们学习监控与告警!

最后更新:2026-03-27