Steampipe & Powerpipe 초기 셋팅 가이드

Steampipe & Powerpipe 가이드북
이민석's avatar
Jul 17, 2024
Steampipe & Powerpipe 초기 셋팅 가이드

개요

다양한 비즈니스, 기술적 요구사항에 따라서
Multi Cloud, Multi Account 환경이 구성되는 경우가 많습니다.

이런 환경에서 효율적인 의사결정을 하기 위해서는
분산된 데이터를 취합, 분석, 시각화할 니즈가 있습니다.

쉽게 생각할 수 있는 솔루션으로는 다음과 같이 있었습니다.

  1. CSP 업체 CLI 와 Insight GUI를 활용

  2. CSP 업체 CLI와 Slack Bot을 연동하여 시스템 구축

  3. 전문 SaaS 선택하여 사용

하지만 각 방법은 아래와 같은 한계점을 가질 뿐만 아니라,
결정적으로 기능 개발 및 유지 비용이 지출된다는 치명적 단점이 존재했습니다.

  1. CSP 업체 CLI : CSP 업체가 늘어날 수록 관리 비용이 발생

  2. Insight GUI : CSP 업체의 Insight GUI에 종속됨

  3. 전문 SaaS 선택 및 사용 : 추가 비용이 지출됨

따라서 오픈소스 툴 2가지를 결합하여
복잡한 데이터를 취합, 분석, 시각화할 환경을 구축하였습니다.

  1. Steampipe

    1. 다양한 Plugins들에 PostgreSQL Query 질의 가능

    2. 기본적으로 Dashboard 구성 지원

  2. Powerpipe

    1. Steampipe Server에 연결하여 강력한 Dashbaord 기능 지원

이 가이드북은 Steampipe, Powerpipe의 구축에 대한 가이드 문서입니다.

Steampipe 설치하기

Homebrew Formulae | steampipe download를 참고하여 설치를 진행합니다.

brew install steampipe

Steampipe Plugin 설정하기

Steampipe는 다양한 공급업체(CSP, GitHub …)들에 대한 Plugin들을 사용하여 PostgreSQL 쿼리 질의를 제공합니다.

여기서는 AWS Query를 위한 aws 플러그인을 설치하여 진행을 하겠습니다. 목적에 따라서 다양한 플러그인을 설치하면 됩니다.

steampipe plugin install aws

Steampipe Connection 설정하기

(aws 플러그인 사용시)
Steampipe는 호스트 머신에 설정된 Default Profile을 설정하도록 되어 있습니다.

저희는 다양한 AWS Account를 가지고 있으며,
이를 통합하여 하나의 조회, 분석, 시각화하고자 하기 때문에 connectionconnection:aggregate를 사용할 것입니다.

Steampipe 환경설정 파일에 엑세스할 수 있습니다.

cd ~/.steampipe/config

공식 문서에 따르면 aws.spc 파일을 참조해서 Steampipe가 작동하게 됩니다. Using Aggregators 문서를 참조하여 다음과 같이 aws.spc 파일을 수정해줍시다.

connection "aws" {
  plugin = "aws"
  type   = "aggregator"
  connections = ["<ID_1>", "<ID_2>", "<ID_3>"]
}

connection "<ID_1>" {
  plugin      = "hub.steampipe.io/plugins/turbot/aws@latest"
  regions     = ["*"]
}

connection "<ID_2>" {
  plugin      = "hub.steampipe.io/plugins/turbot/aws@latest"
  profile     = "<PROFILE_2>"
  regions     = ["*"]
}

connection "<ID_3>" {
  plugin      = "hub.steampipe.io/plugins/turbot/aws@latest"
  profile     = "<PROFILE_3>"
  regions     = ["*"]
}%                                                                                                         

수정 이후, 아래 명령어를 입력하면 AWS Credentials을 이용해서 연결된 Connections들에 대한 정보를 조회할 수 있습니다.

steampipe query
select
  account_id as "Account ID",
  account_aliases ->> 0 as "Alias",
  organization_id as "ORG ID",
  organization_master_account_email as "ORG Master Email",
  organization_master_account_id as "Organization Master ID"
from
  aws_account;

아래와 같은 출력 결과를 확인할 수 있습니다.

+------------+---------+----------+--------------------+-----------------+
| Account ID | Alias   | ORG ID   | ORG Master Email   | ORG Master ID   |
+------------+---------+----------+--------------------+-----------------+
| <ID>       | <ALIAS> | <ORG_ID> | <ORG_MASTER_EMAIL> | <ORG_MASTER_ID> |
| <ID>       | <ALIAS> | <ORG_ID> | <ORG_MASTER_EMAIL> | <ORG_MASTER_ID> |
| <ID>       | <ALIAS> | <ORG_ID> | <ORG_MASTER_EMAIL> | <ORG_MASTER_ID> |
+------------+---------+----------+--------------------+-----------------+

Steampipe Table Schema 조회하기

일반적인 PostgreSQL에서는 다음과 같이 스키마 조회를 합니다.

SELECT 
    column_name, 
    data_type, 
    character_maximum_length, 
    is_nullable, 
    column_default
FROM 
    information_schema.columns
WHERE 
    table_name = 'aws_ec2_instance';

하지만 Steampipe에서는 다음과 같이 스키마 조회를 진행합니다.

.tables
.inspect <TABLE_NAME>;

예를 들어 다음과 같이 aws_ec2_instance 테이블의 스키마를 조회할 수 있습니다.

.inspect aws_ec2_instance

Steampipe Table Select 쿼리 실행하기

일반적인 PostgreSQL DML SELECT 문법과 거의 동일하게 AWS Plugin Select 질의가 가능합니다.

SELECT
  account_id,
  instance_id
FROM  aws_ec2_instance
LIMIT 3;

Steampipe Service 실행하기

후술할 여러 이유 때문에, 대쉬보드 구성을 Powerpipe에서 진행을 할 것입니다.
Steampipe PostgreSQL Query만 사용할 것이기 때문에 다음 명령어로 백그라운드 서비스로 Steampipe를 실행해주세요.

steampipe service start
steampipe service status

Powerpipe 설치하기

Downloads | Powerpipe 문서를 참조하여 설치를 진행합니다.

brew install turbot/tap/powerpipe

powerpipe -v

powerpipe mod init

powerpipe mod install github.com/turbot/powerpipe-mod-aws-compliance

Powerpipe Dashboard 실행하기

다음 명령어를 통해서 Powerpipe Dashboard를 실행해주세요.

powerpipe server

이후 아래 경로에 접속하여 텅빈 대쉬보드를 확인할 수 있습니다.

http://localhost:9033

여기까지 진행했다면 Steampipe & Powerpipe 실습 준비가 완료되었습니다.

Share article
RSSPowered by inblog