started on auth
authorJoey Hess <joeyh@joeyh.name>
Tue, 9 Jul 2024 21:30:55 +0000 (17:30 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 9 Jul 2024 21:30:55 +0000 (17:30 -0400)
Command/P2PHttp.hs
P2P/Http.hs
P2P/Http/State.hs
P2P/Http/Types.hs
doc/design/p2p_protocol_over_http/draft1.mdwn
doc/git-annex-p2phttp.mdwn

index b9596c14e7a9d50677faf5f92b949b270d8fc898..d38408479350c2a0420b4600df31a00b92ad6e96 100644 (file)
@@ -24,7 +24,16 @@ import Control.Concurrent.STM
 cmd :: Command
 cmd = command "p2phttp" SectionPlumbing
        "communicate in P2P protocol over http"
-       paramNothing (withParams seek)
+       paramNothing (seek <$$> optParser)
+
+data Options = Options
+       { cmdParams :: CmdParams
+       , authEnvOption :: Bool
+       , authEnvHttpOption :: Bool
+       , readOnlyOption :: Bool
+       , appendOnlyOption :: Bool
+       , wideOpenOption :: Bool
+       }
 
 seek :: CmdParams -> CommandSeek
 seek ["server"] = startConcurrency commandStages $
index f015f372e88e4e0c6d4e8bee34a1d6b7af2d6cae..ff91e6e2840fa4d749166a1d48198dc18a638c98 100644 (file)
@@ -119,6 +119,7 @@ type GetAPI
        :> BypassUUIDs
        :> AssociatedFileParam
        :> OffsetParam
+       :> AuthHeader
        :> StreamGet NoFraming OctetStream
                (Headers '[DataLengthHeader] (SourceIO B.ByteString))
 
@@ -132,6 +133,7 @@ serveGet
        -> [B64UUID Bypass]
        -> Maybe B64FilePath
        -> Maybe Offset
+       -> Maybe Auth
        -> Handler (Headers '[DataLengthHeader] (S.SourceT IO B.ByteString))
 serveGet = undefined
 
@@ -143,6 +145,7 @@ clientGet
        -> [B64UUID Bypass]
        -> Maybe B64FilePath
        -> Maybe Offset
+       -> Maybe Auth
        -> ClientM (Headers '[DataLengthHeader] (S.SourceT IO B.ByteString))
 clientGet (ProtocolVersion ver) = case ver of
        3 -> v3 V3
@@ -563,3 +566,5 @@ type OffsetParam = QueryParam "offset" Offset
 type DataLengthHeader = Header "X-git-annex-data-length" Integer
 
 type LockIDParam = QueryParam' '[Required] "lockid" LockID
+
+type AuthHeader = Header "Authorization" Auth
index b8b0c54d1b9ca3105e63157994e6e1bac913a3d8..c076e91505d604d942c7385967390cef6f247a73 100644 (file)
@@ -26,12 +26,14 @@ import Control.Concurrent.STM
 
 data P2PHttpServerState = P2PHttpServerState
        { acquireP2PConnection :: AcquireP2PConnection
+       , getServerMode :: GetServerMode
        , openLocks :: TMVar (M.Map LockID Locker)
        }
 
-mkP2PHttpServerState :: AcquireP2PConnection -> IO P2PHttpServerState
-mkP2PHttpServerState acquireconn = P2PHttpServerState
+mkP2PHttpServerState :: AcquireP2PConnection -> GetServerMode -> IO P2PHttpServerState
+mkP2PHttpServerState acquireconn getservermode = P2PHttpServerState
        <$> pure acquireconn
+       <*> pure getservermode
        <*> newTMVarIO mempty
 
 withP2PConnection
@@ -61,6 +63,8 @@ withP2PConnection apiver st cu su bypass connaction = do
                , connectionServerMode = P2P.ServeReadWrite -- XXX auth
                }
 
+type GetServerMode = IsSecure -> Maybe BasicAuthData -> Maybe P2P.ServerMode
+
 data ConnectionParams = ConnectionParams
        { connectionProtocolVersion :: P2P.ProtocolVersion
        , connectionServerUUID :: UUID
index cf081715689f8ff10c2831928acbf27c1b5583e2..db061a23a8a5fba266132f26e1f842a21867c695 100644 (file)
@@ -98,6 +98,12 @@ data LockResult = LockResult Bool (Maybe LockID)
 newtype UnlockRequest = UnlockRequest Bool
        deriving (Show, Generic, NFData)
 
+-- Not using servant's build-in basic authentication support,
+-- because whether authentication is needed depends on server
+-- configuration.
+data Auth = Auth T.Text T.Text
+       deriving (Show, Generic, NFData)
+
 newtype ConnectionKeepAlive = ConnectionKeepAlive T.Text
 
 connectionKeepAlive :: ConnectionKeepAlive
index 688e29f93546e6abfde63c589f6d837af71f7f3a..24dccea7c010dd02561d769a3f864b4d24d0c683 100644 (file)
@@ -19,16 +19,15 @@ underlying data is.
 
 ## authentication
 
-A git-annex protocol endpoint can optionally operate in readonly mode without
-authentication.
+Some requests need authentication. Which requests do depends on the
+configuration of the HTTP server. When a request needs authentication,
+it will fail with 401 Unauthorized.
 
-Authentication is required to make any changes.
+Authentication is done using HTTP basic auth. The realm to use when
+authenticating is "git-annex".
 
-Authentication is done using HTTP basic auth. 
-
-The user is recommended to only authenticate over HTTPS, since otherwise
-HTTP basic auth (as well as git-annex data) can be snooped. But some users
-may want git-annex to use HTTP in eg a LAN.
+Note that HTTP basic auth is not encrypted so is only secure when used
+over HTTPS.
 
 ## protocol version
 
@@ -82,15 +81,13 @@ It is not part of the P2P protocol per se, but is provided to let
 other clients than git-annex easily download the content of keys from the
 http server.
 
-When the key is not present on the server, this returns a 404 Not Found.
+When the key is not present on the server, it will respond
+with 404 Not Found.
 
 ### GET /git-annex/v3/key/$key
 
 Get the content of a key from the server.
 
-This is designed so it can be used both by a peer in the P2P protocol,
-and by a regular HTTP client that just wants to download a file.
-
 Example:
 
     > GET /git-annex/v3/key/SHA1--foo&associatedfile=bar&clientuuid=79a5a1f4-07e8-11ef-873d-97f93ca91925&serveruuid=ecf6d4ca-07e8-11ef-8990-9b8c1f696bf6 HTTP/1.1
index f4758ed9556ae480c9c62f0bcc3471e5a7fdd531..f192bef51bd598a301c5598d57b8c896feaca5d3 100644 (file)
@@ -4,7 +4,7 @@ git-annex-p2phttp - HTTP server for git-annex P2P protocol
 
 # SYNOPSIS
 
-git-annex p2phttp [params ...]
+git-annex p2phttp
 
 # DESCRIPTION
 
@@ -12,6 +12,45 @@ This allows a git-annex repository to be accessed over HTTP.
 It is the git-annex equivilant of git-http-backend(1), for serving
 a repository over HTTP with write access for authenticated users.
 
+# OPTIONS
+
+* `--authenv`
+
+  Allows users to be authenticated with a username and password.
+  For security, this only allows authentication when the user connects over
+  HTTPS.
+
+  To configure the passwords, set environment variables
+  like `GIT_ANNEX_P2PHTTP_PASSWORD_alice=foo123`
+
+  The permissions of users can also be configured by setting
+  environment variables like 
+  `GIT_ANNEX_P2PHTTP_PERMISSIONS_alice=readonly`. The value
+  can be either "readonly" or "appendonly". When this is not set,
+  the default is to give the user full write access.
+
+* `--authenv-http`
+
+  Like `--authenv`, but allows authentication when the user connects
+  over HTTP. This is not secure, since HTTP basic authentication is not
+  encrypted.
+
+* `--readonly`
+
+  Allows unauthenticated users to read the repository, but not make
+  modifications to it.
+
+* `--appendonly`
+
+  Allows unauthenticated users to read the repository, and store data in
+  it, but not remove data from it.
+
+* `--wideopen`
+
+  Gives unauthenticated users full access to the repository.
+
+  Please think carefully before enabling this option.
+
 # SEE ALSO
 
 [[git-annex]](1)