forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Gloo TCP_TLS transport (pytorch#56442)
Summary: Pull Request resolved: pytorch#56442 Test Plan: Imported from OSS Reviewed By: malfet Differential Revision: D27896285 Pulled By: pbelevich fbshipit-source-id: 589af59ca4c7c9bab2329f079382c09b71cfcf9e
- Loading branch information
1 parent
96fce78
commit 96e1a83
Showing
7 changed files
with
169 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from datetime import datetime, timedelta | ||
from tempfile import mkdtemp | ||
from cryptography.hazmat.primitives import serialization | ||
from cryptography.hazmat.primitives.asymmetric import rsa | ||
from cryptography import x509 | ||
from cryptography.x509.oid import NameOID | ||
from cryptography.hazmat.primitives import hashes | ||
|
||
temp_dir = mkdtemp() | ||
print(temp_dir) | ||
|
||
|
||
def genrsa(path): | ||
key = rsa.generate_private_key( | ||
public_exponent=65537, | ||
key_size=2048, | ||
) | ||
with open(path, "wb") as f: | ||
f.write(key.private_bytes( | ||
encoding=serialization.Encoding.PEM, | ||
format=serialization.PrivateFormat.TraditionalOpenSSL, | ||
encryption_algorithm=serialization.NoEncryption(), | ||
)) | ||
return key | ||
|
||
|
||
def create_cert(path, C, ST, L, O, key): | ||
subject = issuer = x509.Name([ | ||
x509.NameAttribute(NameOID.COUNTRY_NAME, C), | ||
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, ST), | ||
x509.NameAttribute(NameOID.LOCALITY_NAME, L), | ||
x509.NameAttribute(NameOID.ORGANIZATION_NAME, O), | ||
]) | ||
cert = x509.CertificateBuilder().subject_name( | ||
subject | ||
).issuer_name( | ||
issuer | ||
).public_key( | ||
key.public_key() | ||
).serial_number( | ||
x509.random_serial_number() | ||
).not_valid_before( | ||
datetime.utcnow() | ||
).not_valid_after( | ||
# Our certificate will be valid for 10 days | ||
datetime.utcnow() + timedelta(days=10) | ||
).add_extension( | ||
x509.BasicConstraints(ca=True, path_length=None), critical=True, | ||
).sign(key, hashes.SHA256()) | ||
# Write our certificate out to disk. | ||
with open(path, "wb") as f: | ||
f.write(cert.public_bytes(serialization.Encoding.PEM)) | ||
return cert | ||
|
||
|
||
def create_req(path, C, ST, L, O, key): | ||
csr = x509.CertificateSigningRequestBuilder().subject_name(x509.Name([ | ||
# Provide various details about who we are. | ||
x509.NameAttribute(NameOID.COUNTRY_NAME, C), | ||
x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, ST), | ||
x509.NameAttribute(NameOID.LOCALITY_NAME, L), | ||
x509.NameAttribute(NameOID.ORGANIZATION_NAME, O), | ||
])).sign(key, hashes.SHA256()) | ||
with open(path, "wb") as f: | ||
f.write(csr.public_bytes(serialization.Encoding.PEM)) | ||
return csr | ||
|
||
|
||
def sign_certificate_request(path, csr_cert, ca_cert, private_ca_key): | ||
cert = x509.CertificateBuilder().subject_name( | ||
csr_cert.subject | ||
).issuer_name( | ||
ca_cert.subject | ||
).public_key( | ||
csr_cert.public_key() | ||
).serial_number( | ||
x509.random_serial_number() | ||
).not_valid_before( | ||
datetime.utcnow() | ||
).not_valid_after( | ||
# Our certificate will be valid for 10 days | ||
datetime.utcnow() + timedelta(days=10) | ||
# Sign our certificate with our private key | ||
).sign(private_ca_key, hashes.SHA256()) | ||
with open(path, "wb") as f: | ||
f.write(cert.public_bytes(serialization.Encoding.PEM)) | ||
return cert | ||
|
||
|
||
ca_key = genrsa(temp_dir + "/ca.key") | ||
ca_cert = create_cert(temp_dir + "/ca.pem", u"US", u"New York", u"New York", u"Gloo Certificate Authority", ca_key) | ||
|
||
pkey = genrsa(temp_dir + "/pkey.key") | ||
csr = create_req(temp_dir + "/csr.csr", u"US", u"California", u"San Francisco", u"Gloo Testing Company", pkey) | ||
|
||
cert = sign_certificate_request(temp_dir + "/cert.pem", csr, ca_cert, ca_key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
CREATE_TEST_CERT="$(dirname "${BASH_SOURCE[0]}")/create_test_cert.py" | ||
TMP_CERT_DIR=$(python "$CREATE_TEST_CERT") | ||
|
||
openssl verify -CAfile "${TMP_CERT_DIR}/ca.pem" "${TMP_CERT_DIR}/cert.pem" | ||
|
||
export GLOO_DEVICE_TRANSPORT=TCP_TLS | ||
export GLOO_DEVICE_TRANSPORT_TCP_TLS_PKEY=${TMP_CERT_DIR}/pkey.key | ||
export GLOO_DEVICE_TRANSPORT_TCP_TLS_CERT=${TMP_CERT_DIR}/cert.pem | ||
export GLOO_DEVICE_TRANSPORT_TCP_TLS_CA_FILE=${TMP_CERT_DIR}/ca.pem | ||
|
||
time python test/run_test.py --include distributed/test_c10d_gloo --verbose --determine-from="$DETERMINE_FROM" -- ProcessGroupGlooTest | ||
|
||
unset GLOO_DEVICE_TRANSPORT | ||
unset GLOO_DEVICE_TRANSPORT_TCP_TLS_PKEY | ||
unset GLOO_DEVICE_TRANSPORT_TCP_TLS_CERT | ||
unset GLOO_DEVICE_TRANSPORT_TCP_TLS_CA_FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters