설치 가이드

Contexa AI Native Zero Trust 플랫폼을 Spring 프로젝트에 적용합니다. CLI 자동 설치 또는 수동 설정 중 선택할 수 있습니다.

빠른 설치 (권장)

Contexa CLI를 설치하고 하나의 명령으로 모든 설정을 자동으로 완료합니다.

1단계 — CLI 설치

Shell (Linux / macOS)
curl -fsSL https://install.ctxa.ai | sh

권한 오류(Permission Denied) 발생 시 — 시스템 공용 디렉토리(예: /usr/local/bin)에 쓰기 작업을 수행하면서 권한 오류가 발생할 경우, sudo sh를 사용하여 권한을 상승시켜 실행하십시오:

curl -fsSL https://install.ctxa.ai | sudo sh

PowerShell (Windows)
irm https://install.ctxa.ai/install.ps1 | iex

Windows 사용자 안내 — PowerShell 5.1 이상에서 동작합니다. 스크립트가 자동으로 SHA-256 체크섬을 검증하고 %LOCALAPPDATA%\Programs\Contexacontexa.exe를 설치한 뒤 PATH 안내를 출력합니다. Git Bash 또는 WSL을 사용하시는 경우 위의 Linux/macOS 명령을 그대로 사용하셔도 됩니다.

또는 contexa-security/contexa-cli 릴리스 페이지에서 contexa-win-x64.exe를 직접 다운로드하여 PATH에 배치하셔도 됩니다.

2단계 — 프로젝트 초기화

Shell
cd your-spring-project
contexa init

CLI가 대화형으로 설정을 안내합니다:

  • 프로젝트 유형 — 신규 프로젝트 (FULL) 또는 레거시 시스템 (SANDBOX)
  • AI 보안 모드 — 관찰만 또는 즉시 차단
  • AI / LLM 모델 — Ollama (로컬), OpenAI, Anthropic
  • 인프라 — Standard (PostgreSQL + Ollama, 단일 서버 인메모리)가 기본. PoC/엔터프라이즈 시연용 분산 모드(Redis + Kafka 포함)는 contexa init --distributed 로 활성화

CLI가 자동으로 수행하는 작업:

  • 빌드 파일에 spring-boot-starter-contexa 의존성 추가
  • application.yml에 올바른 설정 구성
  • 인프라용 docker-compose.yml 생성
  • Docker 컨테이너 시작 및 AI 모델 다운로드

3단계 — 어노테이션 추가

Java
@EnableAISecurity
@SpringBootApplication
public class MyApplication {
    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }
}

// AI Zero Trust로 보호할 엔드포인트에 추가
@Protectable
@GetMapping("/api/customers")
public List<Customer> getCustomers() { ... }

4단계 — 애플리케이션 시작

Shell
./gradlew bootRun

설정 완료. AI 기반 Zero Trust 보안이 활성화되었습니다. @Protectable 엔드포인트에 대한 모든 요청이 AI에 의해 실시간 분석됩니다.

레거시 시스템 연동 (SANDBOX 모드)

프로젝트에 이미 자체 인증 시스템이 있다면 SANDBOX 모드를 사용하세요. 기존 로그인을 수정하지 않고 AI 보안을 추가합니다.

Java
@EnableAISecurity(
    mode = SecurityMode.SANDBOX,
    authObjectLocation = AuthObjectLocation.SESSION,
    authObjectAttribute = "loginUser"  // 레거시 세션 속성명
)
@SpringBootApplication
public class LegacyApplication { }

사이드 이펙트 제로 — SANDBOX 모드는 기존 보안에 간섭하지 않습니다. 로그인 페이지, 세션 관리, 접근 제어가 그대로 유지됩니다. Contexa는 @Protectable 엔드포인트에서만 동작합니다.

사전 요구 사항

CLI 및 수동 설치 모두에 필요합니다:

요구 사항 버전 용도
Java 17+ 런타임 (Gradle 툴체인으로 구성)
Spring Boot 3.x 애플리케이션 프레임워크
Docker 최신 버전 인프라 서비스 (PostgreSQL, Ollama)

분산 배포 (PoC / 엔터프라이즈 시연)contexa init --distributed 를 실행하면 PostgreSQL + Ollama 에 더해 Redis, Kafka, Zookeeper 컨테이너를 자동 생성하고 contexa.infrastructure.mode: DISTRIBUTED, spring-kafka, redisson 의존성까지 자동 추가합니다. 운영 배포는 Kubernetes + Helm 을 권장합니다.

수동 설치

CLI를 사용하지 않으려면 다음 단계를 수동으로 진행합니다.

1. 의존성 추가

Gradle (Groovy)
dependencies {
    implementation 'ai.ctxa:spring-boot-starter-contexa:0.1.0'
}
Maven
<dependency>
    <groupId>ai.ctxa</groupId>
    <artifactId>spring-boot-starter-contexa</artifactId>
    <version>0.1.0</version>
</dependency>

2. 인프라 시작

Shell
# Standard 모드 (PostgreSQL + Ollama)
docker compose up -d

# AI 모델 다운로드
docker exec contexa-ollama ollama pull qwen2.5:14b
docker exec contexa-ollama ollama pull mxbai-embed-large

# PoC/시연용 분산 모드 (PostgreSQL + Ollama + Redis + Kafka)
# contexa init --distributed 를 실행하면 docker-compose.yml 에 모두 포함됩니다
docker compose up -d

3. 인프라 서비스

서비스 이미지 포트 모드
PostgreSQL pgvector/pgvector:pg16 5432 Standard
Ollama ollama/ollama:latest 11434 Standard
Redis redis:7.2-alpine 6379 Distributed
Kafka cp-kafka:7.4.0 9092 Distributed

문제 해결

@EnableAISecurity 시동 오류 가이드

수동 설치로 spring-boot-starter-contexa 만 추가하고 @EnableAISecurity 를 선언하면, 시동 시점에 다음 세 가지 오류가 순서대로 노출될 수 있습니다. contexa-cli 가 자동으로 추가하는 의존성은 spring-boot-starter-contexa 한 개뿐이므로, 나머지는 사용자가 본인 빌드에 직접 추가해야 합니다. 각 오류마다 원인과 해결책을 정확히 표시합니다.

오류 1 — contexa.datasource.url must be configured for @EnableAISecurity

전체 메시지: java.lang.IllegalStateException: contexa.datasource.url must be configured for @EnableAISecurity. Use a dedicated Contexa database by default; sharing the application database requires explicit POC approval.

원인 — Contexa 는 보안 정책·세션·벡터 인덱스를 사용자 운영 DB 와 분리된 전용 PostgreSQL 에 저장합니다. @EnableAISecurity 가 활성화되면 contexa.datasource.url 이 반드시 설정되어 있어야 하며, 미설정 시 ContexaDataSourceIsolation 검증이 즉시 실패합니다.

해결 — 사용자 application.yml 에 contexa 전용 데이터소스 설정을 추가합니다.

application.yml
contexa:
  datasource:
    url: jdbc:postgresql://localhost:5432/contexa
    username: ${CONTEXA_DB_USERNAME:contexa}
    password: ${CONTEXA_DB_PASSWORD:contexa1234!@#}
    driver-class-name: org.postgresql.Driver
    isolation:
      contexa-owned-application: true

운영 DB 와 동일 인스턴스에 별도 스키마로 두려면 운영팀과 사전 승인 후 같은 URL 을 사용하실 수 있습니다. 기본은 별도 DB(권장).

오류 2 — No Spring AI ChatModel is configured for CONTEXA

전체 메시지: No Spring AI ChatModel is configured for CONTEXA. Add at least one Spring AI chat provider starter to your application dependencies (for example org.springframework.ai:spring-ai-starter-model-openai, org.springframework.ai:spring-ai-starter-model-anthropic, or org.springframework.ai:spring-ai-starter-model-ollama), then configure the matching provider under spring.ai.*

원인 — Contexa 의 LLM 티어 자동 설정(CoreLLMTieredAutoConfiguration) 이 ChatModel 빈을 요구하지만, classpath 에 Spring AI provider starter 가 없습니다. spring-boot-starter-contexa 는 ChatModel starter 를 transitive 의존성으로 끌고 오지 않습니다 — 어떤 provider(Ollama/OpenAI/Anthropic) 를 쓰실지는 사용자 결정이라서입니다.

해결 — 본인이 사용하실 provider starter 한 개 이상을 빌드에 추가하시고, 매칭 설정을 spring.ai.* 아래에 두십시오.

build.gradle (Ollama 예시)
dependencies {
    implementation 'ai.ctxa:spring-boot-starter-contexa:0.1.0'
    // 아래는 @EnableAISecurity 사용 시 직접 추가 (provider 1개 이상)
    implementation 'org.springframework.ai:spring-ai-starter-model-ollama'
}
application.yml (Ollama 예시)
spring:
  ai:
    ollama:
      base-url: http://localhost:11434
      chat:
        options:
          model: qwen2.5:14b
          keep-alive: "24h"
      embedding:
        enabled: true
        model: mxbai-embed-large

OpenAI 또는 Anthropic 사용 시 spring-ai-starter-model-openai / spring-ai-starter-model-anthropic 으로 교체하시고 spring.ai.openai.* / spring.ai.anthropic.* 에 API 키를 설정하십시오.

오류 3 — rag-vector capability unresolved / SecurityDecisionPostProcessor 미생성

전체 메시지(요약): [ContexaCapability] rag-vector ... Resolve rag-vector first; SecurityDecisionPostProcessor is created only after UnifiedVectorService is available.

원인@EnableAISecurity 의 의사결정 후처리기(SecurityDecisionPostProcessor) 가 UnifiedVectorService 를 의존하고, 그 뿌리에는 Spring AI VectorStore 빈이 있습니다. classpath 에 pgvector 벡터스토어 starter 가 없으면 rag-vector capability 가 미해결되어 후속 빈 트리가 생성되지 않습니다.

해결 — pgvector 벡터스토어 starter 를 추가하시고, contexa.vectorstore.pgvector.* 를 설정합니다. PostgreSQL 컨테이너는 pgvector/pgvector:pg16 이미지를 사용하셔야 vector 확장이 자동 활성화됩니다.

build.gradle
dependencies {
    implementation 'org.springframework.ai:spring-ai-starter-vector-store-pgvector'
}
application.yml
contexa:
  vectorstore:
    pgvector:
      table-name: vector_store
      index-type: HNSW
      distance-type: COSINE_DISTANCE
      dimensions: 1024
      initialize-schema: true

왜 contexa-cli 가 spring-ai-* 를 자동 추가하지 않는가 — Spring AI provider/벡터스토어 starter 를 모든 사용자에게 자동 주입하면 @EnableAISecurity 를 선언하지 않은 사용자 앱에서도 PgVectorStore / ChatModel 빈이 생성되려 시도하면서 시동이 깨집니다. Contexa 의 contract 는 "한 줄(spring-boot-starter-contexa)만 추가, 나머지는 사용자 결정" 입니다. contexa init 종료 시점에도 next.steps 에 위 의존성 라인을 그대로 출력해 드립니다.

인프라 문제 해결

컨테이너 이름 충돌 — The container name "/contexa-postgres" is already in use

전체 메시지(요약): Error response from daemon: Conflict. The container name "/contexa-postgres" is already in use by container "<hash>". You have to remove (or rename) that container to be able to reuse that name.

이어서 contexa-cli 가 출력: × Docker start failed. Run manually: docker compose up -d

원인 — 같은 이름의 컨테이너(contexa-postgres, contexa-ollama 등) 가 이미 호스트에 존재합니다. Docker 데몬은 같은 이름의 컨테이너 두 개를 동시에 가질 수 없습니다. 보통 다음 두 케이스입니다:

  • 이전 contexa init 실행이 만든 컨테이너가 그대로 살아있음 → 그대로 사용해도 무방
  • 다른 프로젝트가 같은 이름을 점유 중 → 그쪽을 정리하거나 simulate 격리 모드로 전환

해결 방법 1 — 기존 컨테이너 그대로 사용 (권장, 데이터 보존)

Shell
# 1) 기존 컨테이너가 떠있는지 확인
docker ps --filter "name=contexa-" --format "table {{.Names}}\t{{.Status}}"

# 2) 떠있다면 그대로 두고 애플리케이션만 시작
./gradlew bootRun

해결 방법 2 — 기존 컨테이너 제거 후 재생성 (데이터 손실 주의)

Shell
# 정지 + 제거 (볼륨은 보존)
docker rm -f contexa-postgres contexa-ollama
# 분산 모드도 같이 정리하려면
docker rm -f contexa-redis contexa-zookeeper contexa-kafka

# 다시 시작
contexa init --distributed

해결 방법 3 — 격리된 시뮬레이션 모드로 전환 (운영 컨테이너 보호)

Shell
contexa init --simulate

--simulate 옵션은 컨테이너 이름 prefix 를 ctxa-sim- 로 분리하고 포트도 +20000 으로 띄워, 운영 컨테이너와 충돌 없이 사이드 바이 사이드로 사용할 수 있습니다.

문제 해결 방법
PostgreSQL 연결 거부 Docker 실행 확인: docker ps. 포트 5432 사용 여부 확인.
Ollama 연결 거부 컨테이너 로그 확인: docker logs contexa-ollama. 포트 11434 확인.
AI 모델 미발견 모델 다운로드: docker exec contexa-ollama ollama pull qwen2.5:14b... pull mxbai-embed-large
vector 확장 누락 (PostgreSQL) 이미지를 pgvector/pgvector:pg16 으로 사용하시거나, 기존 DB 라면 CREATE EXTENSION IF NOT EXISTS vector; 를 한 번 실행하십시오.
포트 충돌 기본 포트: PostgreSQL 5432, Ollama 11434, Redis 6379, Kafka 9092
contexa init — 화살표 키 미작동 Windows: Git Bash에서 winpty contexa init 사용, 또는 Windows Terminal에서 실행

도움이 필요하신가요?설정 레퍼런스를 확인하거나 GitHub Discussions를 방문하세요.