Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit d2f1fb2

Browse files
author
shin-
committed
removed auth session (tokens stay valid until expired)
1 parent 1ecaa79 commit d2f1fb2

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

docker_registry/toolkit.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,6 @@ def response(data=None, code=200, headers=None, raw=False):
9292
return flask.current_app.make_response((data, code, h))
9393

9494

95-
def check_session():
96-
session = flask.session
97-
if not session:
98-
logger.debug('check_session: Session is empty')
99-
return False
100-
if 'from' in session and get_remote_ip() != session['from']:
101-
logger.debug('check_session: Wrong source ip address')
102-
session.clear()
103-
return False
104-
# Session is valid
105-
return session.get('auth') is True
106-
107-
10895
def validate_parent_access(parent_id):
10996
cfg = config.load()
11097
if cfg.standalone:
@@ -120,7 +107,7 @@ def validate_parent_access(parent_id):
120107
if index_endpoint is None:
121108
index_endpoint = 'https://index.docker.io'
122109
index_endpoint = index_endpoint.strip('/')
123-
url = '{0}/v1/images/{1}/{2}/{3}'.format(
110+
url = '{0}/v1/images/{1}/{2}/layer/{3}/access'.format(
124111
index_endpoint, full_repos_name[0], full_repos_name[1], parent_id
125112
)
126113
headers = {'Authorization': flask.request.headers.get('authorization')}
@@ -228,7 +215,6 @@ def check_token(args):
228215
# Token is valid, we create a session
229216
session = flask.session
230217
session['repository'] = auth.get('repository')
231-
session['auth'] = True
232218
if is_ssl() is False:
233219
# We enforce the IP check only when not using SSL
234220
session['from'] = get_remote_ip()
@@ -270,9 +256,12 @@ def parse_content_signature(s):
270256
def requires_auth(f):
271257
@functools.wraps(f)
272258
def wrapper(*args, **kwargs):
273-
if check_signature() is True or check_session() is True \
274-
or check_token(kwargs) is True:
275-
return f(*args, **kwargs)
259+
session = flask.session
260+
if check_signature() is True or check_token(kwargs) is True:
261+
if 'from' not in session or session['from'] == get_remote_ip():
262+
return f(*args, **kwargs)
263+
else:
264+
session.clear()
276265
headers = {'WWW-Authenticate': 'Token'}
277266
return api_error('Requires authorization', 401, headers)
278267
return wrapper

0 commit comments

Comments
 (0)