add a note about need to reinit when checking out a different branch
[jelmer/etckeeper.git] / README
1 etckeeper is a collection of tools to let /etc be stored in a git
2 repository. It hooks into apt to automatically commit changes made to /etc
3 during package upgrades. It uses `metastore` to track file metadata that
4 git does not normally support, but that is important for /etc, such as the
5 permissions of `/etc/shadow`. It's quite modular and configurable, while
6 also being simple to use if you understand the basics of working with git.
7
8
9 ## security warnings
10
11 First, a big warning: By checking /etc into revision control, you are
12 creating a copy of files like /etc/shadow that must remain secret. Anytime
13 you have a copy of a secret file, it becomes more likely that the file
14 contents won't remain secret. etckeeper is careful about file permissions,
15 and will make sure that repositories it sets up don't allow anyone but root
16 to read their contents. However, you *also* must take care when cloning
17 or copying these repositories, not to allow anyone else to see the data.
18
19 Since git mushes all the files into packs under the .git directory, the
20 whole .git directory content needs to be kept secret. Also, since git
21 doesn't keep track of the mode of files like the shadow file, it will check
22 it out world readable, before etckeeper fixes the permissions. The tutorial
23 has some examples of safe ways to avoid these problems when cloning an /etc
24 repository.
25
26 Also note that `etckeeper init` runs code stored in the git repository.
27 So don't use it on git repositories from untrusted sources.
28
29
30 ## what etckeeper does
31
32 etckeeper has special support to handle changes to /etc caused by
33 installing and upgrading packages. Before apt installs packages,
34 `etckeeper pre-apt` will check that /etc contains no uncommitted changes.
35 After apt installs packages, `etckeeper post-apt` will add any new
36 interesting files to the repository, and commit the changes.
37
38 git is designed as a way to manage source code, not as a way to manage
39 arbitrary directories like /etc. This means it has a few limitations that
40 etckeeper has to work around. These include file metadata storage,
41 empty directories, and special files.
42
43 git has only limited tracking of file metadata, being able to track the
44 executable bit, but not other permissions or owner info. So file metadata
45 storage is handled by `metastore`. Amoung other chores, `etckeeper init`
46 sets up a `pre-commit` hook that uses `metastore` to store metadata about
47 file owners, permissions, and even extended attributes into a
48 `/etc/.metadata` file. This metadata is stored in git along with everything
49 else, and can be applied if the repo should need to be checked back out.
50
51 git cannot track empty directories, but they can be significant sometimes
52 in /etc. So the `pre-commit` hook also stores information that can be used
53 to recreate the empty directories in a `/etc/.etckeeper` file.
54
55 git doesn't support several special files that you _probably_ won't have in
56 /etc, such as unix sockets, named pipes, hardlinked files (but softlinks
57 are fine), and device files. The `pre-commit` hook will warn if your /etc
58 contains such special files.
59
60
61 ## tutorial
62
63 A quick walkthrough of using etckeeper. The `etckeeper init` command
64 initialises an /etc/.git/ repository. This command is careful to never
65 overwrite existing files or directories in /etc. It will create a `.gitignore`
66 if one doesn't already exist, sets up git hooks if they don't already exist,
67 and so on. It does *not* commit any files into to git, but does `git-add` all
68 interesting files for an initial commit.
69
70         etckeeper init
71
72 Now you might want to use git status to check that it includes all
73 the right files, and none of the wrong files. And you can edit the
74 .gitignore and so forth. Once you're ready, it's time to commit:
75
76         cd /etc
77         git commit -m "initial checkin"
78         git gc # pack git repo to save a lot of space
79
80 After this first commit, you can use regular git commands to handle
81 further changes:
82
83         passwd someuser
84         git status
85         git commit -a -m "changed a password"
86
87 Rinse, lather, repeat.
88
89 etckeeper hooks into apt so changes to interesting files in /etc caused by
90 installing or upgrading packages will automatically be committed. Here
91 "interesting" means files that are not ignored by `.gitignore`.
92
93 You can use any git commands you like, but do keep in mind that, if you
94 check out a different branch or an old version, git is operating directly
95 on your system's /etc. But if you do decide to check out a branch or tag,
96 make sure you run "etckeeper init" again, to get any metadata changes:
97
98         git checkout april_first_joke_etc
99         etckeeper init
100
101 Often it's better to clone /etc to elsewhere and do potentially dangerous
102 stuff in a staging directory. You can clone the repository using git-clone,
103 but be careful that the directory it's cloned into starts out mode 700, to
104 prevent anyone else from seeing files like shadow, before `etckeeper init`
105 fixes their permissions:
106
107         mkdir /my/workdir
108         cd /my/workdir
109         chmod 700 .
110         git clone /etc
111         cd etc
112         etckeeper init .
113         chmod 755 ..
114
115 Another common reason to clone the repository is to make a backup to a
116 server. When using git-push to create a new remote clone, make sure the new
117 remote clone is mode 700! (And, obviously, only push over a secure
118 transport like ssh, and only to a server you trust.)
119
120         ssh server 'mkdir /etc-clone; cd /etc-clone; chmod 700 .; git init'
121         git push ssh://server/etc-clone master
122
123 Of course, it's also possible to pull changes from a server onto client
124 machines, to deploy changes to /etc. You might even set up branches for
125 each machine and merge changes between them. Once /etc is under version
126 control, the sky's the limit..
127
128
129 ## configuration
130
131 etckeeper uses `run-parts` to run the executable files in
132 `/etc/etckeeper/$command.d/`. You can modify these files, or add your own
133 custom files. Each individual file is short, simple, and does only one
134 action.
135
136 For example, here's how to configure it to run `git gc` after each apt run,
137 which will save a lot of disk space:
138
139         cd /etc/etckeeper/post-apt.d
140         (echo '#!/bin/sh' ; echo 'exec git-gc') > 99git-gc
141         chmod +x 99git-gc
142         git add .
143         git-commit -m "run git-gc after each apt run"
144
145 Here's how to disable the automatic commits after each apt run, while still
146 letting it git-add new files and git-rm removed ones:
147
148         chmod -x /etc/etckeeper/post-apt.d/75git-commit
149
150 Note that the etckeeper commands are careful to not hardcode anything about
151 git. If you want to use some other revision control system, that's
152 theoretically possible to accomplish by just changing the files in
153 /etc/etckeeper/. If you do this, please let me know.
154
155
156 ## inspiration
157
158 Two blog posts provided inspiration for techniques used by etckeeper:
159 * http://www.jukie.net/~bart/blog/20070312134706
160 * http://bryan-murdock.blogspot.com/2007/07/put-etc-under-revision-control-with-git.html
161
162 isisetup (http://www.isisetup.ch/) has some of the same aims as etckeeper,
163 however, unlike it, etckeeper does not aim to be a git porcelain with its
164 own set of commands for manipulating the /etc repository. Instead,
165 etckeeper provides a simple setup procedure and hooks for setting up an /etc
166 repsository, and then gets out of your way; you manage the repository using
167 regular git commands.
168
169
170 ## license
171
172 etckeeper is licensed under version 2 or greater of the GNU GPL.
173
174
175 ## author
176
177 Joey Hess <joey@kitenet.net>