【发布时间】:2019-01-31 16:27:19
【问题描述】:
我正在 AWS 的一个 EC2 实例上部署 CSR 1000v。
这是我用于身份验证的 python 代码,以便使用路由器中已启用的 RESTCONF。
import requests
import pprint
from aws_requests_auth.aws_auth import AWSRequestsAuth
def get_json(interface):
authaws = AWSRequestsAuth(aws_access_key='AWS_ACCESS_KEY',
aws_secret_access_key='AWS_SECRET_ACCESS_KEY',
aws_host='ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com',
aws_region='us-west-2',
aws_service='compute')
source = 'https://ec2-xx-xx-xx-xx.us-west-2.compute.amazonaws.com/restconf/data/'
module = 'ietf-interfaces:'
container = 'interfaces'
leaf = '/interface=' + interface
options = ''
url = source + module + container + leaf + options
headers = {'Content-type': 'application/yang-data+json', 'Accept': 'application/yang-data+json'}
r = requests.get(url, auth=authaws, headers=headers, verify=False)
return r.json()
if __name__ == '__main__':
interface = 'GigabitEthernet1'
pprint.pprint(get_json(interface))
这是我执行后得到的。
server@zsz:~/shared_files$ python get_one_interface.py
/usr/local/lib/python2.7/dist-packages/urllib3/connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings
InsecureRequestWarning)
{u'errors': {u'error': [{u'error-tag': u'access-denied',
u'error-type': u'protocol'}]}}
显然,无法进行身份验证。
对于aws_access_key 和aws_secret_access_key,我是从IAM 控制台获得的。我什至生成了新的,但仍然无法正常工作。
【问题讨论】:
-
第一个问题似乎与 SSL 证书验证有关,因此您应该对此进行调查。证书验证显然是安全通信中防止 MITM 攻击的重要功能。相关:stackoverflow.com/questions/27981545/…
-
@jarmod SSL证书验证相关问题已解决。但是错误仍然存在。
{u'errors': {u'error': [{u'error-tag': u'access-denied', u'error-type': u'protocol'}]}} -
我不熟悉restconf,但你确定AWS凭证在这里真的有效吗?它们是针对 AWS 服务进行身份验证的凭证。
-
@jarmod 好吧,HTTP(S) 流量是允许的。否则,我不知道如何检查身份验证凭据。我认为这是这里的主要问题。
-
我认为了解更多有关与 netconf 交互以及您在 EC2 实例上安装的 netconf 服务器的身份验证要求的信息会很好。您可能需要使用 ncclient 包中的管理器,使用特定于 nc 的身份验证连接到 netconf 管理器,然后从那里检索功能。见pypi.org/project/ncclient
标签: python amazon-web-services amazon-ec2 cisco ietf-restconf