forge
Clone
https://git.tahinli.com/Tahinli/forge.git
0 watching0 forksRustAGPL-3.07.1 MiB490f099Tahinli7 hours ago322 commits
| 1 | //! Who may use the container registry, and the challenge that asks a client for credentials. |
| 2 | //! |
| 3 | //! A request may carry no credentials (anonymous), a personal access token as HTTP Basic or as a |
| 4 | //! Bearer token (the `packages` scope is needed for anything but public reads), or a short-lived |
| 5 | //! bearer token that `GET /v2/token` issued. Permissions are checked on every request against the |
| 6 | //! identity, so a bearer token only names who is calling and expires quickly. |
| 7 | |
| 8 | use User; |
| 9 | use oci as rules; |
| 10 | use ; |
| 11 | use ; |
| 12 | use ; |
| 13 | use StatusCode; |
| 14 | use headers; |
| 15 | use Response; |
| 16 | |
| 17 | use oci_error; |
| 18 | use crate; |
| 19 | use crateclient_ip; |
| 20 | use crate; |
| 21 | use crateAppState; |
| 22 | |
| 23 | /// Lifetime of a bearer token from `GET /v2/token`, in seconds. |
| 24 | pub const TOKEN_TTL_SECS: i64 = 300; |
| 25 | |
| 26 | /// The scope the challenge names for a repository. |
| 27 | const ACTIONS: &str = "pull,push"; |
| 28 | |
| 29 | /// The caller of a registry request. `user` is `None` for anonymous callers. |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | /// The repository a request names, as its owner and package stand now. |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | /// Resolves the caller from the `Authorization` header. A bearer token this forge issued is |
| 42 | /// verified here; anything else goes to the personal access token check the API uses. A bad |
| 43 | /// credential is a 401 with the challenge, so the client can ask again. |
| 44 | pub async |
| 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 | /// Resolves the repository `name` for `caller`. A write needs the owner, an org owner, or the |
| 83 | /// instance admin, and a signed-in caller. A read of a missing or private image is refused |
| 84 | /// without saying which: anonymous callers get the challenge, signed-in ones 404 or 403. |
| 85 | pub async |
| 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 | |
| 146 | |
| 147 | |
| 148 | |
| 149 | |
| 150 | |
| 151 | |
| 152 | |
| 153 | |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | /// The 401 that asks for credentials. It names the token endpoint, and the repository's scope when |
| 167 | /// the request names one. |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | /// The 403 for a signed-in caller who may not do the thing. |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | /// Logs an internal failure and answers 500 in the registry's error body. |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | /// Maps a package permission failure to a refusal. |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | /// Logs an internal failure and boxes the 500 as a refusal. |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | /// The current time in seconds since the epoch. |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 |