]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - doc/tips/untrusted_git_push.mdwn
(no commit message)
[git.ikiwiki.info.git] / doc / tips / untrusted_git_push.mdwn
1 [[!meta date="2008-10-24 15:47:18 -0400"]]
3 This tip will describe how to allow anyone on the planet to `git push`
4 changes into your wiki, without needing a special account. All a user needs
5 to know is:
7         git clone git://your.wiki/path
8         # now modify any of the files the wiki would let you modify on the web
9         git push
11 This is a wonderful thing to set up for users, because then they can work
12 on the wiki while offline, and they don't need to mess around with web
13 browsers.
15 ## security
17 But, you might be wondering, how can this possibly be secure. Won't users
18 upload all sorts of garbage, change pages you don't want them to edit, and so
19 on.
21 The key to making it secure is configuring ikiwiki to run as your git
22 repository's `pre-receive` hook. There it will examine every change that
23 untrusted users push into the wiki, and reject pushes that contain changes
24 that cannot be made using the web interface.
26 So, unless you have the [[plugins/attachment]] plugin turned on,
27 non-page files cannot be added. And if it's turned on, whatever
28 `allowed_attachments` checks you have configured will also check files
29 pushed into git.
31 And, unless you have the [[plugins/remove]] plugin turned on, no
32 files can be deleted.
34 And if you have `locked_pages` configured, then it will also affect what's
35 pushed into git.
37 Untrusted committers will also not be able to upload files with strange
38 modes, or push to any branch except for the configured `gitorigin_branch`,
39 or manipulate tags.
41 One thing to keep an eye on is uploading large files. It may be easier to
42 do this via git push than using the web, and that could be abused.
44 Also, no checking is done that the authors of commits are right, so people
45 can make a commit that pretends to be done by someone else.
47 ## user setup
49 Add a dedicated user who will push in untrusted commits. This user should have
50 a locked password, and `git-shell` asĀ its shell.
52         root@bluebird:/home/joey>adduser --shell=/usr/bin/git-shell --disabled-password anon
53         Adding user `anon' ...
55 ## ikiwiki setup
57 You should set up ikiwiki before turning on anonymous push in git. 
59 Edit your wiki's setup file, and uncomment the lines for
60 `git_test_receive_wrapper` and `untrusted_committers`.
62         # git pre-receive hook to generate
63         git_test_receive_wrapper => '/srv/git/ikiwiki.info/.git/hooks/pre-receive',
64         # unix users whose commits should be checked by the pre-receive hook
65         untrusted_committers => ['anon'],
67 The `git_test_receive_wrapper` will become the git `pre-receive` hook. The
68 `untrusted_committers` list is the list of unix users who will be pushing in
69 untrusted changes. It should *not* include the user that ikiwiki normally runs
70 as.
72 Once you're done modifying the setup file, don't forget to run
73 `ikiwiki --setup ikiwiki.setup --refresh --wrappers` on it.
75 ## git setup
77 You'll need to arrange the permissions on your bare git repository so that
78 user anon can write to it. One way to do it is to create a group, and put
79 both anon and your regular user in that group. Then make the bare git
80 repository owned and writable by the group. See [[rcs/git]] for some more
81 tips on setting up a git repository with multiple committers.
83 Note that anon should *not* be able to write to the `srcdir`, *only* to the bare git
84 repository for your wiki.
86 If you want to allow git over `ssh`, generate a ssh key for anon, and
87 publish the *private* key for other people to use. This is optional; you
88 can use `git-daemon` instead and not worry about keys.
90 Now set up `git-daemon`. It will need to run as user `anon`, and be
91 configured to export your wiki's bare git repository. I set it up as
92 follows in `/etc/inetd.conf`, and ran `/etc/init.d/openbsd-inetd restart`.
94         git     stream  tcp     nowait  anon          /usr/bin/git-daemon git-daemon --inetd --export-all --interpolated-path=/srv/git/%H%D /srv/git
96 At this point you should be able to `git clone git://your.wiki/path` from
97 anywhere, and check out the source to your wiki. But you won't be able to
98 push to it yet, one more change is needed to turn that on. Edit the
99 `config` file of your bare git repository, and allow `git-daemon` to
100 receive pushes:
102         [daemon]
103                 receivepack = true
105 Now pushes should be accepted, and your wiki immediatly be updated. If it
106 doesn't, check your git repo's permissions, and make sure that the
107 `post-update` and `pre-receive` hooks are suid so they run as the user who
108 owns the `srcdir`.
110 ## infelicities
112 If a user tries to push a changeset that ikiwiki doesn't like, it will
113 abort the push before refs are updated. However, the changeset will still
114 be present in your repository, wasting space. Since nothing refers to it,
115 it will be expired eventually. You can speed up the expiry by running `git
116 prune`.