SCM & CI,CD

.gitignore 관리하기

  • -
반응형

현재 저의 GitHub에 올려놓은 프로젝트는 DB 정보를 담고 있는 root-context의 정보가 그대로 노출되어 있습니다.

서비스 중인 프로그램이 아닌 개인 프로젝트 용도기 때문에 괜찮을 수 있지만 보안과 관련된 정보들은 항상 조심해야 합니다. 특히 실무에서는 DB 서버, 파일 서버, 계정 등 외부로 알려지면 안되는 정보들이 많기 때문에 유의해야 합니다.

 

오늘 포스팅할 내용은 GitHub에 보안과 관련된 민감한 정보들은 따로 분리하여 관리하는 방법에 관한 것입니다.


gitignore

Git에서는 원하지 않는 파일들을 저장소에 올리지 않도록 할 수 있는 gitignore 파일을 제공한다. 서두에 언급했던 보안과 관련된 정보들이나 저장소에 올리지 않아도 되는 파일들(백업파일,클래스 파일)을 올리지 않도록 설정함으로써 각종 문제를 방지한다.

 

이제 gitignore를 활용해 DB 정보를 숨겨보는 작업을 해보자.

 

1) 프로젝트 - webapp 아래 config 폴더를 생성한다.

 

2) config 폴더에 파일을 생성한다. [New - File]

 

3) DB 접속 정보를 아래 파일에 입력한다.

 

config.properties

spring.datasource.driverClassname=net.sf.log4jdbc.sql.jdbcapi.DriverSpy
spring.datasource.url=jdbc:log4jdbc:mysql://127.0.0.1:3306/shxdb
spring.datasource.username=root
spring.datasource.password=0591

 

4) root-context.xml 파일을 수정한다.

먼저 외부에서 설정한 프로퍼티 파일을 불러오고(context 네임스페이스의 property-placeholder 태그를 추가하면 외부 프로퍼티 파일을 등록할 수 있다)

프로퍼티 치환자를 입력해준다.

 

root-context.xml

<context:property-placeholder location="/config/config.properties" />

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">		
	<property name="driverClassName" value="${spring.datasource.driverClassname}" />		
	<property name="url" value="${spring.datasource.url}" />		
	<property name="username" value="${spring.datasource.username}" />
	<property name="password" value="${spring.datasource.password}" />	
</bean>

 

*<context:property-placeholder> 태그를 사용하기 위해서 context 접두어에 대한 네임스페이스를 http://www.springframework.org/schema/context로 지정하고 네임스페이스와 관련된 xml 스키마 경로(schemaLocation)를 지정해 주어야 한다.

 

5) gitignore 파일을 생성한다.

gitignore 파일을 생성하는 방법은 Repository 생성시 만들 수도 있고, git 터미널을 이용하는 방법도 있지만 이클립스와 연동해 사용중인 경우에는 아래와 같이 만들 수 있다.

 

6-1) 아래 사이트에 접속해 Eclipse를 검색한다.

 

gitignore.io

Create useful .gitignore files for your project

www.toptal.com

 

6-2) 생성된 소스를 복사해 붙여 넣는다. (gitignore)

.gitignore

# Created by https://www.toptal.com/developers/gitignore/api/eclipse
# Edit at https://www.toptal.com/developers/gitignore?templates=eclipse

### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# CDT- autotools
.autotools

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Annotation Processing
.apt_generated/
.apt_generated_test/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet

# Uncomment this line if you wish to ignore the project description file.
# Typically, this file would be tracked if it contains build/dependency configurations:
#.project

### Eclipse Patch ###
# Spring Boot Tooling
.sts4-cache/

# End of https://www.toptal.com/developers/gitignore/api/eclipse

 

7) 생성된 소스 중간에 2)에서 생성한 config.properties 파일을 제외할 수 있도록 추가해준다.

 

8) 이제 수정된 파일을 저장소로 push 해보면 config.properties 파일은 저장소로 올라가지 않고 root-context.xml 에서 더이상 DB 정보를 확인할 수 없게된 것을 확인할 수 있다.

반응형

'SCM & CI,CD' 카테고리의 다른 글

[Jenkins]Git 연동  (0) 2023.03.16
[Jenkins]SFTP를 이용해 배포하기  (0) 2022.08.11
[Jenkins]GitHub 연동 (2)  (0) 2020.12.08
[Jenkins]GitHub 연동 (1)  (0) 2020.12.08
[버전관리]Eclipse + Git 연동  (0) 2020.12.04
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.