Skip to content

Allow for an access mechanism to be specified in the .lfsconfig file - #1122

Merged
technoweenie merged 1 commit into
git-lfs:masterfrom
rjbell4:allowaccess
Apr 6, 2016
Merged

technoweenie merged 1 commit into
git-lfs:masterfrom
rjbell4:allowaccess

Conversation

@rjbell4

@rjbell4 rjbell4 commented Apr 4, 2016

Copy link
Copy Markdown
Contributor

I don't know if you want a change this simple, as I don't know the original intent, but as mentioned in issue #1121, I was hoping to describe the access of my LFS URL as "private" in the same .lfsconfig as where I define the URL itself. I think it makes the most sense to have this data be co-resident. However, git-lfs won't allow me to put this content in the .lfsconfig. This simple change allows me to define it there.

@technoweenie

Copy link
Copy Markdown
Contributor

Looks great, just needs a test :)

diff --git a/test/test-config.sh b/test/test-config.sh
index b185396..b6438a8 100755
--- a/test/test-config.sh
+++ b/test/test-config.sh
@@ -15,12 +15,25 @@ begin_test "default config"

   git config --file=.gitconfig lfs.url http://gitconfig-file-ignored
   git config --file=.lfsconfig lfs.url http://lfsconfig-file
+  git config --file=.lfsconfig lfs.http://lfsconfig-file.access lfsconfig
   git lfs env | tee env.log
-  grep "Endpoint=http://lfsconfig-file (auth=none)" env.log
+  grep "Endpoint=http://lfsconfig-file (auth=lfsconfig)" env.log

+  # new endpoint url from local git config
+  # access setting no longer applied
   git config lfs.url http://local-lfsconfig
   git lfs env | tee env.log
   grep "Endpoint=http://local-lfsconfig (auth=none)" env.log
+
+  # add the access setting to lfsconfig
+  git config --file=.lfsconfig lfs.http://local-lfsconfig.access lfsconfig
+  git lfs env | tee env.log
+  grep "Endpoint=http://local-lfsconfig (auth=lfsconfig)" env.log
+
+  # add the access setting to git config¡
+  git config lfs.http://local-lfsconfig.access config
+  git lfs env | tee env.log
+  grep "Endpoint=http://local-lfsconfig (auth=config)" env.log
 )
 end_test

This is a failing test on master that should work with this PR.

@rjbell4

rjbell4 commented Apr 5, 2016

Copy link
Copy Markdown
Contributor Author

Thanks for providing the example test. I added it (with just a minor change). I verified that it fails without my proposed change to config.go, and succeeds with the change.

@technoweenie

Copy link
Copy Markdown
Contributor

Awesome, thanks 🤘

@technoweenie
technoweenie merged commit 3671987 into git-lfs:master Apr 6, 2016
@rjbell4
rjbell4 deleted the allowaccess branch April 6, 2016 14:33
@technoweenie technoweenie mentioned this pull request Apr 6, 2016
16 of 17 tasks
chrisd8088 added a commit that referenced this pull request Oct 22, 2026
By default, when the Git LFS client receives a 401 status code
response to an HTTP request, it records the type of authentication
required by the remote host in a local Git configuration option
named "lfs.<url>.access".  On subsequent invocations of the client,
it checks this option's value before making any HTTP requests to
the remote host, and if the option is set, attempts to acquire and
send the appropriate credentials for the host with its first request.
By doing so, the client avoids the need to send a preliminary
request without credentials each time it runs, since such requests
are likely to just receive 401 status code responses.

Users may set "lfs.<url>.access" configuration options in advance
if they know the type of authentication required by a remote host,
and in commit dc4dc8e of PR #1122
we introduced support for the inclusion of "lfs.<url>.access" options
in ".lfsconfig" files.  If an ".lfsconfig" file appears in the top
level of a repository, the Git LFS client will read and parse the
file as a Git configuration file.  For security reasons, though,
only a small subset of options are accepted from ".lfsconfig" files,
and all other options are ignored.

However, in commit dc4dc8e, when
we intended to add the "lfs.<url>.access" option to the subset of
options that are permitted to appear in an ".lfsconfig" file, we
failed to properly constrain the option's name to the "lfs"
configuration section.  Fortunately, there are no other options
defined by Git or Git LFS with a "*.<url>.access" name pattern,
so this oversight does not constitute a security vulnerability on
its own.  The situation would change, though, if support for a
new option which matched the "*.<url>.access" pattern were to be
introduced in the future.

To resolve this concern, we adjust the readGitConfig() function
in our "config" package so that when it parses options from an
".lfsconfig" file, it only accepts those whose final component
matches the string "access" if their initial component matches
the section name "lfs".

We then expand the Go test function we added in a prior commit
and also add a shell integration test to confirm that our changes
are effective and that options of the form "*.<url>.access" are
ignored in ".lfsconfig" files if they do not appear in the "lfs"
configuration section.

Co-authored-by: Aniket Gupta <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants