설명
파일이나 디렉터리를 만들 때 mode를 생략하면 모듈과 실행 환경의 umask에 따라 권한이 달라집니다. 대상이 이미 있으면 기존 권한이 유지될 수 있습니다.
잠재적 영향
읽기 권한이 너무 넓으면 민감한 파일이 노출될 수 있습니다. 쓰기 권한까지 있으면 다른 사용자가 설정을 바꿔 서비스에 영향을 줄 수 있습니다.
해결 방법
create: true, state: touch, state: directory, get_url로 생성하는 대상마다 필요한 mode를 지정하세요. 8진수 값은 "0600"처럼 따옴표로 감싸세요. 디렉터리에는 경로를 통과할 실행 권한도 필요합니다. 배포 후 소유자, 그룹, 실제 권한을 확인하세요.
예시
아래 URL과 경로를 환경에 맞게 바꾸세요.
변경 전
yaml
- name: create config file without explicit permissions
ansible.builtin.lineinfile:
path: /etc/sample.conf
create: true
line: sample=true
- name: download file without explicit permissions
ansible.builtin.get_url:
url: https://example.com/file.txt
dest: /tmp/file.txt
변경 후
yaml
- name: create config file with explicit permissions
ansible.builtin.lineinfile:
path: /etc/sample.conf
create: true
line: sample=true
mode: "0600"
- name: download file with explicit permissions
ansible.builtin.get_url:
url: https://example.com/file.txt
dest: /tmp/file.txt
mode: "0600"
두 작업 모두 일반 파일을 mode: "0600"으로 설정해 소유자만 읽고 쓸 수 있습니다. 다른 서비스 계정도 읽어야 한다면 그 계정에 필요한 읽기 권한을 부여하세요.