我们将Flask应用程序部署到了AWS lambda,并且希望将其访问权限限制为:
通过在AWS Gateway或flask本身中将相应IP列入白名单,很容易实现前两个。但是,后两者比较棘手,因为没有用于位桶管道的静态IP,也没有从Google接收oauth2回调时的静态IP。
我已经查看了Http标头中的引荐来源,以识别有效的Google回调,但可以很容易地对其进行欺骗...
是否有一种将应用程序锁定到上述来源的复杂方法?
这是我到目前为止获得的版本
def whitelist_handler():
whitelist_ips = os.getenv('WHITELIST_IPS')
allow_access = True
if whitelist_ips:
whitelist_ips = whitelist_ips.split(',')
referer = request.headers.get('Referer', '')
whitelist_domains = ['https://accounts.google.com/signin/']
if request.remote_addr not in whitelist_ips and not any([referer.startswith(domain) for domain in whitelist_domains]):
allow_access = False
if not allow_access:
abort(401)
答案 0 :(得分:3)
Bitbucket
对于Bitbucket,管道实际上确实具有on the docs所列的静态IP地址。
Google OAuth
对于OAuth,我不确定您在这里做什么,但是OAuth流程的任何部分都不涉及需要将Web请求发送到您的应用程序的提供商(Google)。 OAuth完全不支持重定向用户(该用户应该已经通过您的其他规则进行访问)。您可以了解有关此流程here的信息。
只要您的规则允许您的用户 IP,那么您无需为Google做任何事情。这就是为什么可以在本地或Intranet应用程序中使用OAuth的原因。