aboutsummaryrefslogtreecommitdiff
path: root/doc/plugins/contrib/signinview.mdwn
blob: 0bfdd9f03b420d778dcaa0433d8da3b15778d736 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
[[!template id=plugin name=signinview core=0 author="[[jcflack]]"]]
[[!tag type/special-purpose]]

This plugin is one implementation approach to a [[todo/zoned ikiwiki]]. It is named
like [[plugins/signinedit]], which requires users to sign in before editing pages.
Similarly, this plugin requires users to sign in before _viewing_ certain pages.
Unlike [[plugins/signinedit]], which _only_ checks that any user is signed in,
this plugin is also similar to [[plugins/lockedit]] in that it checks the user's
identity and a [[ikiwiki/PageSpec]] to determine _which_ pages may be viewed.
It works with any auth methods ikiwiki supports, not only those the `http` server
also understands.

## How to configure

This plugin adds a new function, `do=view`, to ikiwiki's CGI wrapper. It is intended
to be called by the `http` server as an `ErrorDocument` for the `403` (forbidden) error response.

In order to be usable even in shared-hosting situations without full access to
the `http` server configuration files, this plugin requires nothing more than
`.htaccess` files, as long as the server is configured to honor `ErrorDocument` and
`Deny` or `Require` directives in them.

To divide the wiki into a public zone and one or more private zone(s), simply place
`Require all denied` (Apache 2.4), `Deny from All` (Apache 2.2), or the equivalent
directive for the server and version in use, on the topmost directory of any private
zone, either in an `.htaccess` file, or in the server configuration file if possible.
Any location outside of these will continue to be served as normal public static
ikiwiki content.

Then, if the `{$cgiurl}` is, for example, `/cgi-bin/ikiwiki.cgi`, add the directive

    ErrorDocument 403 /cgi-bin/ikiwiki.cgi?do=view

at the private locations or any ancestor up to the documentroot itself, again either
in a `.htaccess` file or in the server configuration file.

That's it for the server configuration. The server will now punt every request for
private content to the ikiwiki wrapper. Everything else about the authorization
decision--what auth method to use, whether there is just one private zone or different
zones for different users--is handled by ikiwiki using a [[ikiwiki/PageSpec]].

### viewable_pages config option

This option in `ikiwiki.setup` is a [[ikiwiki/PageSpec]] defining which pages can be viewed.
Because one predicate that can be used in a [[ikiwiki/PageSpec]] is `user`, this is enough
to define interesting access rules. For example:

    viewable_pages: >
      ((user(astolfo) or user(basilio)) and team1/*)
      or
      ((user(clotaldo) or user(estrella)) and team2/*)

Note that this defines the conditions to _allow_ viewing, which is opposite the
sense of the [[plugins/lockedit]] plugin, where you define the conditions
to _deny_ editing.

If there are more than a few users in a group, or the specification for accessible
pages is more complex, the [[plugins/contrib/pagespec_alias]] plugin
can be useful to factor things out. Note it currently must [[be patched|plugins/contrib/pagespec_alias/discussion]]
for this to work:

    pagespec_aliases:
      team1: >
        user(astolfo)
        or user(basilio)
      team2: >
        user(clotaldo)
        or user(estrella)
      team1stuff: team1/* or common/*
      team2stuff: team2/* or common/*
    viewable_pages: >
      (team1() and team1stuff())
      or (team2() and team2stuff())

### mime_types config option

Normally, when serving the static pages of an ordinary public site,
the `http` server itself is responsible for identifying the `Content-Type`
of each file. However, for any page that is served by this plugin instead
of directly, the CGI specification makes it [plugin's job](http://tools.ietf.org/html/rfc3875#section-6.3.1),
not the server's, to identify the `Content-Type`.

In the current version, this plugin does that in a dead-simple way. For any page that ikiwiki htmlized
(that is, for which the `pagetype` [[plugin API function|plugins/write]] returns a value),
the type `text/html` is assigned. For anything else, a simple collection of content types and `PageSpec`s
must be configured in the `ikiwiki.setup` file:

    mime_types:
      image/png: '*.png'
      application/pdf: '*.pdf'
      text/css: '*.css'

Anything without a matching rule gets served as `application/octet-stream`, which is
probably not what you want, but a clear sign of what rule needs to be added.

## Other considerations

### Leakage of non-content files

Any CGI code that does what this plugin does, and can serve requested files under the
document root, needs to be careful not to allow viewing of certain sensitive files
that may also be found there, such as `.htaccess`, `.htpasswd`, etc. Instead of trying
to think of all the possible files that should not be served, this plugin takes an
absolutely strict approach: every requested file is looked up in the `%destsources` hash,
containing all the files ikiwiki has generated or placed in the web root.
Any file that _ikiwiki didn't put there_, this plugin _won't touch_. Otherwise, its page
name is now known, and must satisfy the `viewable_pages` `PageSpec`.

This policy is also what allows this plugin to work back through `%pagesources` to
the original source name, needed for the content-type rules described above.

### Cache control

The purpose of a non-public zone can be defeated if there are caching proxies or
other non-private caches that might retain the content this plugin returns.

Caching of the response is automatically forbidden by the HTTP specification
[if there was an `Authorization` header in the request](http://tools.ietf.org/html/rfc7234#section-3.2).
However, this plugin works with any auth method ikiwiki supports, not all of which require
that header, so this plugin always emits response headers to explicitly forbid caching.

Note that nothing precludes an evil caching agent that ignores the rules.

### Other ways to handle `Content-Type`

While it is simple enough to supply a `mime_types` map in `ikiwiki.setup`, it also
duplicates logic that has already been done to death in other places. Another approach
would be to use `File::MimeInfo::Magic`, which is already present if the `filecheck`
plugin is in use.

In a wiki _compiler_, it would be natural to do that content-type determination
at compile time and save it in page state, so this plugin would simply output
the stored type. On the other hand, saving the type for every (non-htmlized?) page
would enlarge the state `Storable` that has to be loaded, and so might not be
faster than typing the file on the fly.

## Obtaining and installing

The `signinview` plugin is [not in github yet](https://github.com/jcflack/ikiwiki/tree/plug-signinview)
(horroars! vaporware!). What _is_ in github at the moment is a preliminary patch I have
[proposed](https://github.com/joeyh/ikiwiki/pull/14),
giving plugins some control over the environment variables that a generated wrapper will preserve.

Depending on the ultimate fate of that patch, I will adjust/rebase and then push the `signinview`
branch itself.