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