'security'에 해당되는 글 18건

  1. 2022.05.11 [Elasticsearch] 8.2.0 Docker Compose 예제.
  2. 2021.08.12 [Elasticsearch] RESTful API + ID:PASSWORD 요청.
  3. 2020.09.03 [Elasticsearch] API Key (중복)
  4. 2020.07.23 [Spring] Spring Security Session Timeout Disable.
  5. 2020.07.07 [Spring] Spring Security 기본 Login Form 제거 및 CSRF 만 사용하기
  6. 2020.06.19 [Elasticsearch] X-pack Security API Key 사용 해 보기
  7. 2020.05.20 [Spring] Spring Security Disabled.
  8. 2020.04.21 [Spring] spring security + javax api 사용에 따른 JDK 버전 문제.
  9. 2020.02.25 [AWS] VPC 부터 EC2 생성해서 SSH 연결해보기
  10. 2017.12.18 [Elasticsearch] Java Security Manager 관련

[Elasticsearch] 8.2.0 Docker Compose 예제.

Elastic/Elasticsearch 2022. 5. 11. 16:42

Elasticsearch 7.x 와 다르게 8.x 에서는 기본 xpack.security.enabled: true 로 실행이 됩니다.

그래서 docker container 구성 시 보안 기능을 사용 하지 않고 예전 처럼 7.x 에서 사용 하듯이 사용 하고자 한다면 아래 예제를 참고해서 사용 하시기 바랍니다.

version: '3.7'
services:
  es-singlenode:
    image: docker.elastic.co/elasticsearch/elasticsearch:8.2.0
    container_name: es-singlenode
    environment:
      - xpack.security.enabled=false
      - node.name=single-node
      - cluster.name=es-singlenode-c
      - discovery.type=single-node
    ports:
      - 9200:9200
      - 9300:9300
    networks:
      - es-bridge
networks:
  es-bridge:
    driver: bridge

저 같은 경우 xpack basic 을 사용 하기는 하지만 보안 기능을 사용 하지는 않습니다.

모두 private subnet 에서 구성해서 사용중이기도 하고 별도 ACL 통제를 통해서 접근 제어도 이루어 지고 있어서 인데요.

판단은 각자가 알아서 하셔야 할 것 같습니다.

 

:

[Elasticsearch] RESTful API + ID:PASSWORD 요청.

Elastic/Elasticsearch 2021. 8. 12. 13:18

분명 어딘가에 기록해 두었는데 이걸 왜 못찾고 있는 거지..ㅡ.ㅡ;

 

http://elastic:password@localhost:9200/test-index

 

elasticsearch 에서 기본 인증을 사용 할 경우 API token 사용 이런게 아니라면 단순하게는 저렇게 보낼 수 있습니다.

 

https://www.ietf.org/rfc/rfc2617.txt

공식 스펙은 위 문서 참고 하시면 됩니다. (Basic Authentication)

 

URL 로 보내기 싫으시면 header 로 보내시면 됩니다.

 

elastic:password 를 base64 인코딩 하시고 "Authorization" 헤더로 값을 보내시면 되겠습니다.

 

KEY : Authorization

VALUE : Basic ZWxhc3RpYzpwYXNzd29yZA==

 

:

[Elasticsearch] API Key (중복)

Elastic/Elasticsearch 2020. 9. 3. 10:16

이전에 작성한 글과 중복 내용이 있습니다.

 

이전 글)

jjeong.tistory.com/1487

 

Elasticsearch + Kibana 사용 시 basic security 설정을 enable 하게 되면 Restful API 사용을 위한 API Key 를 생성 해서 사용을 해야 합니다.

 

Kibana devtools 를 이용해서 할 경우 인증이 되어 있어서 /_security/api_key 사용이 가능 하지만 Postman 과 같은 걸 이용할 경우 id:pwd 를 넣어 줘야 합니다.

[Case 1]
http://elastic:elasticpassword@localhost:9200/_security/api_key

[Case 2]
curl -XPUT -u elastic:elasticpassword "http://localhost:9200/_security/api_key" -d
{
  "name": "team-index-command",
  "expiration": "10m", 
  "role_descriptors": { 
    "role-team-index-command": {
      "cluster": ["all"],
      "index": [
        {
          "names": ["*"],
          "privileges": ["all"]
        }
      ]
    }
  }
}

 

API Key 구조)

- /_security/api_key 를 이용해서 생성을 하면 아래와 같은 값이 나옵니다.

[Request]
POST /_security/api_key
{
  "name": "team-index-command",
  "expiration": "10m", 
  "role_descriptors": { 
    "role-team-index-command": {
      "cluster": ["all"],
      "index": [
        {
          "names": ["*"],
          "privileges": ["all"]
        }
      ]
    }
  }
}

[Response]
{
  "id" : "87cuynIBjKAXtnkobGgo",
  "name" : "team-index-command",
  "expiration" : 1592529999478,
  "api_key" : "OlVGT_Q8RGq1C_ASHW7pGg"
}

- API Key 는 id:api_key 조합으로 base64 encoding 된 값입니다.

base64_encode("87cuynIBjKAXtnkobGgo"+":"+"OlVGT_Q8RGq1C_ASHW7pGg")

 

API Key 를 이용한 Restful API 호출)

$ curl 
  -H "Authorization: ApiKey VGVVOXluSUJHUUdMaHpvcUxDVWo6aUtfSmlEMmdSMy1FUUFpdENCYzF1QQ==" 
  http://localhost:9200/_cluster/health

 

:

[Spring] Spring Security Session Timeout Disable.

ITWeb/개발일반 2020. 7. 23. 07:55

application.yml 또는 properties 파일 내 아래와 같이 선언 하시면 됩니다.

server:
  servlet:
    session:
      timeout: 0

 

:

[Spring] Spring Security 기본 Login Form 제거 및 CSRF 만 사용하기

ITWeb/개발일반 2020. 7. 7. 08:33

사용하다 보면 별의 별 요구사항이 나오게 됩니다.

단순 하게 CSRF 만 사용 하고 싶은데 자꾸 login form 이 나와서 설정만으로 이걸 해결해 보고자 했습니다.

그러나 설정 만으로는 안되더라고요.

 

설정 예시) 비추천

security:
  enable:
    csrf: true
  basic:
    enabled: false

management:
  security:
    enabled: false

 

코드 예시) 추천

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

  @Override
  protected void configure(HttpSecurity httpSecurity) throws Exception {
    httpSecurity.httpBasic().disable();
  }
}

참고 정보)

dependencies {
  implementation 'org.springframework.boot:spring-boot-starter-quartz'
  implementation 'org.springframework.boot:spring-boot-starter-web'

  // thymeleaf
  implementation 'org.thymeleaf.extras:thymeleaf-extras-java8time'
  implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
  implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'

  // spring security
  implementation 'org.springframework.boot:spring-boot-starter-security'
  implementation 'org.springframework.security:spring-security-test'
  implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'

  implementation 'org.webjars:jquery:3.5.0'
  implementation 'org.webjars:jquery-ui:1.12.1'
  implementation 'org.webjars.bower:bootstrap:4.4.0'

  compileOnly 'org.projectlombok:lombok'
  annotationProcessor 'org.projectlombok:lombok'
  providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
  testImplementation('org.springframework.boot:spring-boot-starter-test') {
    exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
  }
}


<meta id="_csrf" name="_csrf" th:content="${_csrf.token}" />
<meta id="_csrf_header" name="_csrf_header" th:content="${_csrf.headerName}" />

let token = $("meta[name='_csrf']").attr("content");
let header = $("meta[name='_csrf_header']").attr("content");

$(function() {
  $(document).ajaxSend(function(e, xhr, options) {
    xhr.setRequestHeader(header, token);
  });
});


spring:
  security:
    user:
      name: admin
      password: admin

 

 

:

[Elasticsearch] X-pack Security API Key 사용 해 보기

Elastic/Elasticsearch 2020. 6. 19. 11:07

Elastic Stack 이 좋은 이유는 기본 Basic license 까지 사용이 가능 하다는 것입니다.

사실 이것 말고도 엄청 많죠 ㅎㅎ 

 

https://www.elastic.co/subscriptions

 

딱 API keys management 까지 사용이 됩니다. ㅎㅎㅎ

 

먼저 사용하기에 앞서서 Elasticsearch 와 Kibana 에 x-pack 사용을 위한 설정을 하셔야 합니다.

 

[Elasticsearch]

- elasticsearch.yml

xpack.monitoring.enabled: true
xpack.ml.enabled: true
xpack.security.enabled: true

xpack.security.authc.api_key.enabled: true
xpack.security.authc.api_key.hashing.algorithm: "pbkdf2"
xpack.security.authc.api_key.cache.ttl: "1d"
xpack.security.authc.api_key.cache.max_keys: 10000
xpack.security.authc.api_key.cache.hash_algo: "ssha256"

위 설정은 기본이기 때문에 환경에 맞게 최적화 하셔야 합니다.

https://www.elastic.co/guide/en/elasticsearch/reference/7.8/security-settings.html#api-key-service-settings

 

[Kibana]

- kibana.yml

xpack:
  security:
    enabled: true
    encryptionKey: "9c42bff2e04f9b937966bda03e6b5828"
    session:
      idleTimeout: 600000
    audit:
      enabled: true

 

이렇게 설정 한 후 id/password 설정을 하시면 됩니다.

 

# bin/elasticsearch-setup-passwords interactive
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
You will be prompted to enter passwords as the process progresses.
Please confirm that you would like to continue [y/N]y

Enter password for [elastic]:
Reenter password for [elastic]:
Enter password for [apm_system]:
Reenter password for [apm_system]:
Enter password for [kibana]:
Reenter password for [kibana]:
Enter password for [logstash_system]:
Reenter password for [logstash_system]:
Enter password for [beats_system]:
Reenter password for [beats_system]:
Enter password for [remote_monitoring_user]:
Reenter password for [remote_monitoring_user]:
Changed password for user [apm_system]
Changed password for user [kibana]
Changed password for user [logstash_system]
Changed password for user [beats_system]

Changed password for user [remote_monitoring_user]
Changed password for user [elastic]

 

이렇게 설정이 끝나면 kibana 에 접속해서 API key 를 생성 하시면 됩니다.

아래 문서는 생성 시 도움이 되는 문서 입니다.

 

www.elastic.co/guide/en/elasticsearch/reference/current/security-privileges.html

www.elastic.co/guide/en/elasticsearch/reference/7.7/security-api-put-role.htmlwww.elastic.co/guide/en/elasticsearch/reference/7.7/defining-roles.htmlwww.elastic.co/guide/en/elasticsearch/reference/7.7/security-api-create-api-key.html

 

Kibana Console 에서 아래와 같이 생성이 가능 합니다.

POST /_security/api_key
{
  "name": "team-index-command",
  "expiration": "10m", 
  "role_descriptors": { 
    "role-team-index-command": {
      "cluster": ["all"],
      "index": [
        {
          "names": ["*"],
          "privileges": ["all"]
        }
      ]
    }
  }
}

{
  "id" : "87cuynIBjKAXtnkobGgo",
  "name" : "team-index-command",
  "expiration" : 1592529999478,
  "api_key" : "OlVGT_Q8RGq1C_ASHW7pGg"
}

생성 이후 사용을 위해서는 

 

- ApiKey 는 id:api_key 를 base64 인코딩 합니다.

base64_encode("87cuynIBjKAXtnkobGgo"+":"+"OlVGT_Q8RGq1C_ASHW7pGg")
==> VGVVOXluSUJHUUdMaHpvcUxDVWo6aUtfSmlEMmdSMy1FUUFpdENCYzF1QQ==
curl -H 
  "Authorization: ApiKey VGVVOXluSUJHUUdMaHpvcUxDVWo6aUtfSmlEMmdSMy1FUUFpdENCYzF1QQ==" 
  http://localhost:9200/_cluster/health

이제 용도와 목적에 맞춰서 API key 를 만들고 사용 하시면 되겠습니다.

 

:

[Spring] Spring Security Disabled.

ITWeb/개발일반 2020. 5. 20. 15:10

spring security 를 사용하면서 테스트를 위해 인증을 off 하고 싶을 때 사용 하면 됩니다.

 

Application main)
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)

application.yml)
security:
  enable:
    csrf: false
  basic:
    enabled: false
  ignored: /**
management:
  security:
    enabled: false

위에서 처럼 두 군데에 적용해 주면 됩니다.

:

[Spring] spring security + javax api 사용에 따른 JDK 버전 문제.

ITWeb/개발일반 2020. 4. 21. 17:56

구글링 하면 많이 나옵니다.

 

spring security 사용 시 JDK 를 11 사용 하게 되면 아래와 같은 오류가 발생 할 떄가 있습니다.

 

에러)

 

Class Not Found javax/xml/bind/DatatypeConverter

 

해당 API 는 JDK 11 에서 삭제 되었기 때문에 그렇습니다.

그래서 해결을 하기 위해서는 두 가지 방법이 있습니다.

 

1. JDK 1.8 을 사용 하거나

2. javax-api dependency 를 잡아 주시면 됩니다.

compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1'

 

:

[AWS] VPC 부터 EC2 생성해서 SSH 연결해보기

Cloud&Container/AWS 2020. 2. 25. 16:30

AWS 에서 쵝 인프라 및 네트워크를 구성 하고 Bastion 설정을 통해 SSH Tunneling 을 해보도록 하겠습니다.

(기억력을 돕기 위해 작성한 내용입니다.)

 

[AWS에서 초기 인프라 및 네트워크 구성 하기]
생성 하는 순서는 아래와 같이 진행을 하시면 됩니다.

1. VPC 생성을 합니다.
2. Subnet 생성을 합니다.
- Public Subnet
- Private Subnet
3. Route Table 생성을 합니다.
- Public Route Table
- Private Route Table
4. Subnet 과 Route Table 연결을 합니다.
5. Internet Gateway 생성을 합니다.
- 인터넷 전용 연결 게이트웨이로 사용 합니다.
6. VPC 와 Internet Gateway 연결을 합니다.
7. Route Table 에서 Internet Gateway 연결을 합니다.
- Public Route Table 을 연결 합니다.
8. Network ACL 과 Security Group 설정을 합니다.
- 생성한 자원들에 대한 접근 제어 설계를 통해 구성 합니다.
- Inbounds, Outbounds


[VPC 생성]
- 생성할 VPC Name tag 를 작성 합니다.
- vpc-startup
- IPv4 CIDR block 을 작성 합니다.
- 10.0.0.0/16
참고 글)
https://jjeong.tistory.com/1405
- IPv6 CIDR block 은 기본 "No IPv6 CIDR Block" 을 선택 합니다.
- Tenancy 는 "Default" 를 선택 합니다.

[Subnet 생성]
- 생성할 Subnet 의 Name tag 를 작성 합니다.
- sbn2a-prd-public
- sbn2b-prd-private
- 연결할 VPC 를 선택 합니다.
- 생성할 Availability Zone 을 선택 합니다.
- VPC CIDR 범위에 속하는 IPv4 CIDR block 을 등록 합니다.
- 10.0.0.0/20
- First IP : 10.0.0.0
- Last IP : 10.0.15.255
- AWS 내 Available IPv4 Addresses : 4091 개

[Route Table 생성]
- 생성할 Route Table 의 Name tag 를 작성 합니다.
- rtb-prd-public
- rtb-prd-private
- 연결할 VPC 를 선택 합니다.

[Subnet 과 Route Table 연결]
- Route Table 정보 화면에서 Subnet Associations 를 선택 합니다.
- Edit subnet associations 를 클릭 합니다.
- 연결할 Subnet 을 선택 합니다.

[Internet Gateway 생성 / VPC 와 연결]
- 생성할 Internet Gateway 의 Name tag 를 작성 합니다.
- 목록에서 생성한 IGW 를 선택 하고 Actions 에서 Attach to VPC 를 통해 연결 합니다.

[Route Table 에 Internet Gateway 연결]
- Public Route Table 에서 Routes 탭의 Edit routes 를 클릭 합니다.
- Add route 를 통해 IGW 를 등록 합니다.
- 0.0.0.0/0

[Network ACL 설정 및 Subnet 연결]
- Public zone 과 Private zone 에 대한 ACL 을 생성 합니다.
- 생성할 ACL 의 Name tag 를 작성 합니다.
- acl-prd-public
- acl-prd-private
- 연결할 VPC 를 선택 합니다.
- Public zone acl 에 SSH Tunnel Gateway 구성을 위한 Inbound Rule 을 생성 합니다.
- 초기 SSH 연결 테스트만 하기 위한 설정 입니다.
- SSH(22), TCP(6), 22, 0.0.0.0/0, ALLOW
- Private zone acl 에 Inbound Rule 을 생성 합니다.
- SSH Tunnel Gateway 에서 접속 할 수 있도록 SSH 오픈 및 Source 제한을 합니다.
- 설정한 ACL 을 Subnet 에 적용 될 수 있도록 연결 설정 합니다.

[Security Group 생성]
- 생성할 Security Group Name 을 작성 합니다.
- 사용할 VPC 를 선택 합니다.
- SSH Tunnel Gateway 구성을 위한 Inbound 를 설정 합니다.
-  SSH, TCP, 22, My IP 로 Add Rule 합니다.
- Outbound 는 All 로 구성 합니다.

여기까지 했으면 VPC, ZONE, Security 에 대한 기본 구성을 해본 것입니다.
이제 EC2 인스턴스를 생성해서 SSH Tunnel 용 Gateway (Bastion) 를 구성해 보도록 하겠습니다. 

[EC2 생성]
- Amazon Linux 2 AMI 를 선택 합니다.
t2.micro 를 선택 합니다. (저는 free tier 적용을 위해 선택 했기 때문에 용도와 목적에 맞게 선택 하시면 됩니다.)
- 생성할 VPC 를 선택 합니다.
- 생성할 Subnet 을 선택 합니다.
- Public IP 할당 여부를 선택 합니다. (Bastion 구성을 위해 Public IP 할당)
- Storage, Tag 설정 이후 Security Group 설정을 합니다.
- Select an existing security group 을 통해 이미 만들어 놓은 것을 선택 합니다.
- Key pair 를 다운받습니다.
- 인스턴스를 시작 합니다.

[SSH 연결]
$ ssh -i ec2key-prd-gw.pem ec2-user@ec2-xxx-xxx-xxx-xxx.ap-northeast-2.compute.amazonaws.com

[ssh-keygen on 맥북]
$ ssh-keygen -t rsa
$ cat .ssh/id_rsa.pub
ssh-rsa .....HENRYJEONG.local

[User 생성]

https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/managing-users.html
[ec2-user@ip-42 ~]$ sudo adduser henryjeong
[ec2-user@ip-42 ~]$ sudo su - henryjeong
[henryjeong@ip-42 ~]$ mkdir .ssh
[henryjeong@ip-42 ~]$ chmod 700 .ssh
[henryjeong@ip-42 .ssh]$ touch authorized_keys
[henryjeong@ip-42 .ssh]$ chmod 600 authorized_keys
[henryjeong@ip-42 .ssh]$ vi authorized_keys

[User 로 접속]
$ ssh henryjeong@xxx.xxx.xxx.xxx
Last login: Tue Feb 25 07:23:45 2020

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
[henryjeong@ip-10-0-6-44 ~]$

# EC2 에 Public IP 는 생성이 되었으나 Public DNS 가 생성되지 않았을 경우 

Your answer

  • Go to console.aws.amazon.com.
  • Go To Services and then VPC.
  • Open Your VPCs.
  • Select your VPC connected to your EC2 and.
  • Choose Select Actions.
  • Click on Edit DNS Hostnames.
  • Then Change DNS hostnames: to YES.
:

[Elasticsearch] Java Security Manager 관련

Elastic/Elasticsearch 2017. 12. 18. 15:45

elasticsearch plugin 을 만들다 보면 보안정책 강화에 따라 permission 에러가 발생 하는 경우가 있습니다.

이럴 경우 아래 내용을 통해서 문제를 해결해 보시기 바랍니다.


[Elasticsearch Java Security Manager]

$ export JAVA_OPTS="${JAVA_OPTS} -Djava.security.policy=file:///path/to/my.policy` ./bin/elasticsearch

# or config/jvm.options

$ vi config/jvm.options

-Djava.security.policy=file:///path/to/my.policy

$ export JAVA_OPTS="${JAVA_OPTS} -Dsecurity.manager.enabled=false` ./bin/elasticsearch

# or config/jvm.options

$ vi config/jvm.options 

-Dsecurity.manager.enabled=false


Example) my.policy

# Ref. https://docs.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html


grant {

permission org.elasticsearch.script.ClassPermission "java.util.Base64"; // allow class

permission org.elasticsearch.script.ClassPermission "java.util.*"; // allow package

permission org.elasticsearch.script.ClassPermission "*"; // allow all (disables filtering basically)

permission java.io.FilePermission "$ES_HOME/config/resource/*", "read"; // allow all files

};


Example) plugin-metadata/plugin-security.policy (recommended)

# Ref. https://www.elastic.co/guide/en/elasticsearch/plugins/current/plugin-authors.html#plugin-authors-jsm

# Ref. https://github.com/elastic/elasticsearch/blob/master/plugins/discovery-gce/src/main/plugin-metadata/plugin-security.policy

: